From: Ben Pfaff Date: Wed, 5 Aug 2009 21:36:21 +0000 (-0700) Subject: datapath: Update sysfs links when network devices are renamed. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0515ceb3e82ecc6160a141017c20ca26ec1a7a5f;p=openvswitch datapath: Update sysfs links when network devices are renamed. We create symlinks from /sys/class/net//brif/ to /sys/class/net//brport, but until now we have never updated the links when network devices are renamed. This commit fixes this problem. (Only the in /sys/class/net//brif/ 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.) --- diff --git a/datapath/datapath.c b/datapath/datapath.c index f4284edc..bf8043b6 100644 --- a/datapath/datapath.c +++ b/datapath/datapath.c @@ -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); diff --git a/datapath/datapath.h b/datapath/datapath.h index 63d92cbb..62c79d43 100644 --- a/datapath/datapath.h +++ b/datapath/datapath.h @@ -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. */ }; diff --git a/datapath/dp_notify.c b/datapath/dp_notify.c index 5b8cf171..f22d8b34 100644 --- a/datapath/dp_notify.c +++ b/datapath/dp_notify.c @@ -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; } diff --git a/datapath/dp_sysfs_if.c b/datapath/dp_sysfs_if.c index 178afbd7..ab928f6c 100644 --- a/datapath/dp_sysfs_if.c +++ b/datapath/dp_sysfs_if.c @@ -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);