X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=datapath%2Fvport-patch.c;h=4fdbcf5278d6558f7f75519b0f96687d9e1554cf;hb=d2bb2799e1b7cf2177140cf4ca8a60312c87625a;hp=4b5137de212acb39b483532cb12ed2c36d0e7710;hpb=e779d8d90d65297473febcf82ec44c9225cc4fe3;p=openvswitch diff --git a/datapath/vport-patch.c b/datapath/vport-patch.c index 4b5137de..4fdbcf52 100644 --- a/datapath/vport-patch.c +++ b/datapath/vport-patch.c @@ -9,6 +9,7 @@ #include #include #include +#include #include "datapath.h" #include "vport.h" @@ -22,23 +23,24 @@ struct device_config { }; struct patch_vport { + struct rcu_head rcu; + char name[IFNAMSIZ]; /* Protected by RTNL lock. */ char peer_name[IFNAMSIZ]; struct hlist_node hash_node; - /* Protected by RCU. */ - struct vport *peer; - - /* Protected by RCU. */ - struct device_config *devconf; + struct vport __rcu *peer; + struct device_config __rcu *devconf; }; /* Protected by RTNL lock. */ static struct hlist_head *peer_table; #define PEER_HASH_BUCKETS 256 +static void update_peers(const char *name, struct vport *); + static inline struct patch_vport *patch_vport_priv(const struct vport *vport) { return vport_priv(vport); @@ -57,7 +59,7 @@ static void assign_config_rcu(struct vport *vport, struct patch_vport *patch_vport = patch_vport_priv(vport); struct device_config *old_config; - old_config = rcu_dereference(patch_vport->devconf); + old_config = rtnl_dereference(patch_vport->devconf); rcu_assign_pointer(patch_vport->devconf, new_config); call_rcu(&old_config->rcu, free_config); } @@ -126,10 +128,15 @@ static struct vport *patch_create(const struct vport_parms *parms) vport_gen_rand_ether_addr(patch_vport->devconf->eth_addr); - /* Make the default MTU fairly large so that it doesn't become the - * bottleneck on systems using jumbo frames. */ + /* Make the default MTU fairly large so that it doesn't become the + * bottleneck on systems using jumbo frames. */ patch_vport->devconf->mtu = 65535; + hlist_add_head(&patch_vport->hash_node, hash_bucket(patch_vport->peer_name)); + + rcu_assign_pointer(patch_vport->peer, vport_locate(patch_vport->peer_name)); + update_peers(patch_vport->name, vport); + return vport; error_free_vport: @@ -151,12 +158,22 @@ static int patch_modify(struct vport *vport, struct odp_port *port) return err; } +static void free_port_rcu(struct rcu_head *rcu) +{ + struct patch_vport *patch_vport = container_of(rcu, + struct patch_vport, rcu); + + kfree(patch_vport->devconf); + vport_free(vport_from_priv(patch_vport)); +} + static int patch_destroy(struct vport *vport) { struct patch_vport *patch_vport = patch_vport_priv(vport); - kfree(patch_vport->devconf); - vport_free(vport); + update_peers(patch_vport->name, NULL); + hlist_del(&patch_vport->hash_node); + call_rcu(&patch_vport->rcu, free_port_rcu); return 0; } @@ -172,30 +189,6 @@ static void update_peers(const char *name, struct vport *vport) rcu_assign_pointer(peer_vport->peer, vport); } -static int patch_attach(struct vport *vport) -{ - struct patch_vport *patch_vport = patch_vport_priv(vport); - - hlist_add_head(&patch_vport->hash_node, hash_bucket(patch_vport->peer_name)); - - rcu_assign_pointer(patch_vport->peer, vport_locate(patch_vport->peer_name)); - update_peers(patch_vport->name, vport); - - return 0; -} - -static int patch_detach(struct vport *vport) -{ - struct patch_vport *patch_vport = patch_vport_priv(vport); - - update_peers(patch_vport->name, NULL); - rcu_assign_pointer(patch_vport->peer, NULL); - - hlist_del(&patch_vport->hash_node); - - return 0; -} - static int patch_set_mtu(struct vport *vport, int mtu) { struct patch_vport *patch_vport = patch_vport_priv(vport); @@ -236,13 +229,13 @@ static const char *patch_get_name(const struct vport *vport) static const unsigned char *patch_get_addr(const struct vport *vport) { const struct patch_vport *patch_vport = patch_vport_priv(vport); - return rcu_dereference(patch_vport->devconf)->eth_addr; + return rcu_dereference_rtnl(patch_vport->devconf)->eth_addr; } static int patch_get_mtu(const struct vport *vport) { const struct patch_vport *patch_vport = patch_vport_priv(vport); - return rcu_dereference(patch_vport->devconf)->mtu; + return rcu_dereference_rtnl(patch_vport->devconf)->mtu; } static int patch_send(struct vport *vport, struct sk_buff *skb) @@ -270,8 +263,6 @@ const struct vport_ops patch_vport_ops = { .create = patch_create, .modify = patch_modify, .destroy = patch_destroy, - .attach = patch_attach, - .detach = patch_detach, .set_mtu = patch_set_mtu, .set_addr = patch_set_addr, .get_name = patch_get_name,