aboutsummaryrefslogtreecommitdiffstats
path: root/net/openvswitch/vport.c
diff options
context:
space:
mode:
authorPravin B Shelar <pshelar@nicira.com>2012-02-22 22:58:59 -0500
committerJesse Gross <jesse@nicira.com>2012-08-22 17:48:55 -0400
commit46df7b814548849deee01f50bc75f8f5ae8cd767 (patch)
tree1663fa6ae46edcba3787c0a4ff839365bb52bcbe /net/openvswitch/vport.c
parent0d7614f09c1ebdbaa1599a5aba7593f147bf96ee (diff)
openvswitch: Add support for network namespaces.
Following patch adds support for network namespace to openvswitch. Since it must release devices when namespaces are destroyed, a side effect of this patch is that the module no longer keeps a refcount but instead cleans up any state when it is unloaded. Signed-off-by: Pravin B Shelar <pshelar@nicira.com> Signed-off-by: Jesse Gross <jesse@nicira.com>
Diffstat (limited to 'net/openvswitch/vport.c')
-rw-r--r--net/openvswitch/vport.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/net/openvswitch/vport.c b/net/openvswitch/vport.c
index 6140336e79d7..9873acea9785 100644
--- a/net/openvswitch/vport.c
+++ b/net/openvswitch/vport.c
@@ -16,10 +16,10 @@
16 * 02110-1301, USA 16 * 02110-1301, USA
17 */ 17 */
18 18
19#include <linux/dcache.h>
20#include <linux/etherdevice.h> 19#include <linux/etherdevice.h>
21#include <linux/if.h> 20#include <linux/if.h>
22#include <linux/if_vlan.h> 21#include <linux/if_vlan.h>
22#include <linux/jhash.h>
23#include <linux/kernel.h> 23#include <linux/kernel.h>
24#include <linux/list.h> 24#include <linux/list.h>
25#include <linux/mutex.h> 25#include <linux/mutex.h>
@@ -27,7 +27,9 @@
27#include <linux/rcupdate.h> 27#include <linux/rcupdate.h>
28#include <linux/rtnetlink.h> 28#include <linux/rtnetlink.h>
29#include <linux/compat.h> 29#include <linux/compat.h>
30#include <net/net_namespace.h>
30 31
32#include "datapath.h"
31#include "vport.h" 33#include "vport.h"
32#include "vport-internal_dev.h" 34#include "vport-internal_dev.h"
33 35
@@ -67,9 +69,9 @@ void ovs_vport_exit(void)
67 kfree(dev_table); 69 kfree(dev_table);
68} 70}
69 71
70static struct hlist_head *hash_bucket(const char *name) 72static struct hlist_head *hash_bucket(struct net *net, const char *name)
71{ 73{
72 unsigned int hash = full_name_hash(name, strlen(name)); 74 unsigned int hash = jhash(name, strlen(name), (unsigned long) net);
73 return &dev_table[hash & (VPORT_HASH_BUCKETS - 1)]; 75 return &dev_table[hash & (VPORT_HASH_BUCKETS - 1)];
74} 76}
75 77
@@ -80,14 +82,15 @@ static struct hlist_head *hash_bucket(const char *name)
80 * 82 *
81 * Must be called with RTNL or RCU read lock. 83 * Must be called with RTNL or RCU read lock.
82 */ 84 */
83struct vport *ovs_vport_locate(const char *name) 85struct vport *ovs_vport_locate(struct net *net, const char *name)
84{ 86{
85 struct hlist_head *bucket = hash_bucket(name); 87 struct hlist_head *bucket = hash_bucket(net, name);
86 struct vport *vport; 88 struct vport *vport;
87 struct hlist_node *node; 89 struct hlist_node *node;
88 90
89 hlist_for_each_entry_rcu(vport, node, bucket, hash_node) 91 hlist_for_each_entry_rcu(vport, node, bucket, hash_node)
90 if (!strcmp(name, vport->ops->get_name(vport))) 92 if (!strcmp(name, vport->ops->get_name(vport)) &&
93 net_eq(ovs_dp_get_net(vport->dp), net))
91 return vport; 94 return vport;
92 95
93 return NULL; 96 return NULL;
@@ -170,14 +173,17 @@ struct vport *ovs_vport_add(const struct vport_parms *parms)
170 173
171 for (i = 0; i < ARRAY_SIZE(vport_ops_list); i++) { 174 for (i = 0; i < ARRAY_SIZE(vport_ops_list); i++) {
172 if (vport_ops_list[i]->type == parms->type) { 175 if (vport_ops_list[i]->type == parms->type) {
176 struct hlist_head *bucket;
177
173 vport = vport_ops_list[i]->create(parms); 178 vport = vport_ops_list[i]->create(parms);
174 if (IS_ERR(vport)) { 179 if (IS_ERR(vport)) {
175 err = PTR_ERR(vport); 180 err = PTR_ERR(vport);
176 goto out; 181 goto out;
177 } 182 }
178 183
179 hlist_add_head_rcu(&vport->hash_node, 184 bucket = hash_bucket(ovs_dp_get_net(vport->dp),
180 hash_bucket(vport->ops->get_name(vport))); 185 vport->ops->get_name(vport));
186 hlist_add_head_rcu(&vport->hash_node, bucket);
181 return vport; 187 return vport;
182 } 188 }
183 } 189 }