datapath: Update sysfs links when network devices are renamed.
[sliver-openvswitch.git] / datapath / dp_notify.c
1 /*
2  * Distributed under the terms of the GNU GPL version 2.
3  * Copyright (c) 2007, 2008, 2009 Nicira Networks.
4  *
5  * Significant portions of this file may be copied from parts of the Linux
6  * kernel, by Linus Torvalds and others.
7  */
8
9 /* Handle changes to managed devices */
10
11 #include <linux/netdevice.h>
12
13 #include "datapath.h"
14
15
16 static int dp_device_event(struct notifier_block *unused, unsigned long event, 
17                 void *ptr) 
18 {
19         struct net_device *dev = ptr;
20         struct net_bridge_port *p;
21         struct datapath *dp;
22
23         p = dev->br_port;
24         if (!p)
25                 return NOTIFY_DONE;
26         dp = p->dp;
27
28         switch (event) {
29         case NETDEV_UNREGISTER:
30                 mutex_lock(&dp->mutex);
31                 dp_del_port(p);
32                 mutex_unlock(&dp->mutex);
33                 break;
34
35         case NETDEV_CHANGENAME:
36                 if (p->port_no != ODPP_LOCAL) {
37                         mutex_lock(&dp->mutex);
38                         dp_sysfs_del_if(p);
39                         dp_sysfs_add_if(p);
40                         mutex_unlock(&dp->mutex);
41                 }
42                 break;
43         }
44         return NOTIFY_DONE;
45 }
46
47 struct notifier_block dp_device_notifier = {
48         .notifier_call = dp_device_event
49 };