mirror of
https://github.com/openvswitch/ovs
synced 2025-09-04 00:05:15 +00:00
netdev-offload: replace netdev_hmap_mutex to netdev_hmap_rwlock
All the kmap lookup operations netdev_ports_flow_del, netdev_ports_get netdev_ifindex_to_odp_port should protected by rdlock without affect each other in the handlers and revalidators Signed-off-by: wenxu <wenxu@ucloud.cn> Signed-off-by: Ben Pfaff <blp@ovn.org>
This commit is contained in:
@@ -362,11 +362,11 @@ netdev_set_hw_info(struct netdev *netdev, int type, int val)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Protects below port hashmaps. */
|
/* Protects below port hashmaps. */
|
||||||
static struct ovs_mutex netdev_hmap_mutex = OVS_MUTEX_INITIALIZER;
|
static struct ovs_rwlock netdev_hmap_rwlock = OVS_RWLOCK_INITIALIZER;
|
||||||
|
|
||||||
static struct hmap port_to_netdev OVS_GUARDED_BY(netdev_hmap_mutex)
|
static struct hmap port_to_netdev OVS_GUARDED_BY(netdev_hmap_rwlock)
|
||||||
= HMAP_INITIALIZER(&port_to_netdev);
|
= HMAP_INITIALIZER(&port_to_netdev);
|
||||||
static struct hmap ifindex_to_port OVS_GUARDED_BY(netdev_hmap_mutex)
|
static struct hmap ifindex_to_port OVS_GUARDED_BY(netdev_hmap_rwlock)
|
||||||
= HMAP_INITIALIZER(&ifindex_to_port);
|
= HMAP_INITIALIZER(&ifindex_to_port);
|
||||||
|
|
||||||
struct port_to_netdev_data {
|
struct port_to_netdev_data {
|
||||||
@@ -384,12 +384,12 @@ struct port_to_netdev_data {
|
|||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
netdev_any_oor(void)
|
netdev_any_oor(void)
|
||||||
OVS_EXCLUDED(netdev_hmap_mutex)
|
OVS_EXCLUDED(netdev_hmap_rwlock)
|
||||||
{
|
{
|
||||||
struct port_to_netdev_data *data;
|
struct port_to_netdev_data *data;
|
||||||
bool oor = false;
|
bool oor = false;
|
||||||
|
|
||||||
ovs_mutex_lock(&netdev_hmap_mutex);
|
ovs_rwlock_rdlock(&netdev_hmap_rwlock);
|
||||||
HMAP_FOR_EACH (data, portno_node, &port_to_netdev) {
|
HMAP_FOR_EACH (data, portno_node, &port_to_netdev) {
|
||||||
struct netdev *dev = data->netdev;
|
struct netdev *dev = data->netdev;
|
||||||
|
|
||||||
@@ -398,7 +398,7 @@ netdev_any_oor(void)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ovs_mutex_unlock(&netdev_hmap_mutex);
|
ovs_rwlock_unlock(&netdev_hmap_rwlock);
|
||||||
|
|
||||||
return oor;
|
return oor;
|
||||||
}
|
}
|
||||||
@@ -414,13 +414,13 @@ netdev_ports_flow_flush(const struct dpif_class *dpif_class)
|
|||||||
{
|
{
|
||||||
struct port_to_netdev_data *data;
|
struct port_to_netdev_data *data;
|
||||||
|
|
||||||
ovs_mutex_lock(&netdev_hmap_mutex);
|
ovs_rwlock_rdlock(&netdev_hmap_rwlock);
|
||||||
HMAP_FOR_EACH (data, portno_node, &port_to_netdev) {
|
HMAP_FOR_EACH (data, portno_node, &port_to_netdev) {
|
||||||
if (data->dpif_class == dpif_class) {
|
if (data->dpif_class == dpif_class) {
|
||||||
netdev_flow_flush(data->netdev);
|
netdev_flow_flush(data->netdev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ovs_mutex_unlock(&netdev_hmap_mutex);
|
ovs_rwlock_unlock(&netdev_hmap_rwlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct netdev_flow_dump **
|
struct netdev_flow_dump **
|
||||||
@@ -431,7 +431,7 @@ netdev_ports_flow_dump_create(const struct dpif_class *dpif_class, int *ports)
|
|||||||
int count = 0;
|
int count = 0;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
ovs_mutex_lock(&netdev_hmap_mutex);
|
ovs_rwlock_rdlock(&netdev_hmap_rwlock);
|
||||||
HMAP_FOR_EACH (data, portno_node, &port_to_netdev) {
|
HMAP_FOR_EACH (data, portno_node, &port_to_netdev) {
|
||||||
if (data->dpif_class == dpif_class) {
|
if (data->dpif_class == dpif_class) {
|
||||||
count++;
|
count++;
|
||||||
@@ -450,7 +450,7 @@ netdev_ports_flow_dump_create(const struct dpif_class *dpif_class, int *ports)
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ovs_mutex_unlock(&netdev_hmap_mutex);
|
ovs_rwlock_unlock(&netdev_hmap_rwlock);
|
||||||
|
|
||||||
*ports = i;
|
*ports = i;
|
||||||
return dumps;
|
return dumps;
|
||||||
@@ -463,15 +463,15 @@ netdev_ports_flow_del(const struct dpif_class *dpif_class,
|
|||||||
{
|
{
|
||||||
struct port_to_netdev_data *data;
|
struct port_to_netdev_data *data;
|
||||||
|
|
||||||
ovs_mutex_lock(&netdev_hmap_mutex);
|
ovs_rwlock_rdlock(&netdev_hmap_rwlock);
|
||||||
HMAP_FOR_EACH (data, portno_node, &port_to_netdev) {
|
HMAP_FOR_EACH (data, portno_node, &port_to_netdev) {
|
||||||
if (data->dpif_class == dpif_class
|
if (data->dpif_class == dpif_class
|
||||||
&& !netdev_flow_del(data->netdev, ufid, stats)) {
|
&& !netdev_flow_del(data->netdev, ufid, stats)) {
|
||||||
ovs_mutex_unlock(&netdev_hmap_mutex);
|
ovs_rwlock_unlock(&netdev_hmap_rwlock);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ovs_mutex_unlock(&netdev_hmap_mutex);
|
ovs_rwlock_unlock(&netdev_hmap_rwlock);
|
||||||
|
|
||||||
return ENOENT;
|
return ENOENT;
|
||||||
}
|
}
|
||||||
@@ -484,16 +484,16 @@ netdev_ports_flow_get(const struct dpif_class *dpif_class, struct match *match,
|
|||||||
{
|
{
|
||||||
struct port_to_netdev_data *data;
|
struct port_to_netdev_data *data;
|
||||||
|
|
||||||
ovs_mutex_lock(&netdev_hmap_mutex);
|
ovs_rwlock_rdlock(&netdev_hmap_rwlock);
|
||||||
HMAP_FOR_EACH (data, portno_node, &port_to_netdev) {
|
HMAP_FOR_EACH (data, portno_node, &port_to_netdev) {
|
||||||
if (data->dpif_class == dpif_class
|
if (data->dpif_class == dpif_class
|
||||||
&& !netdev_flow_get(data->netdev, match, actions,
|
&& !netdev_flow_get(data->netdev, match, actions,
|
||||||
ufid, stats, attrs, buf)) {
|
ufid, stats, attrs, buf)) {
|
||||||
ovs_mutex_unlock(&netdev_hmap_mutex);
|
ovs_rwlock_unlock(&netdev_hmap_rwlock);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ovs_mutex_unlock(&netdev_hmap_mutex);
|
ovs_rwlock_unlock(&netdev_hmap_rwlock);
|
||||||
return ENOENT;
|
return ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -505,7 +505,7 @@ netdev_ports_hash(odp_port_t port, const struct dpif_class *dpif_class)
|
|||||||
|
|
||||||
static struct port_to_netdev_data *
|
static struct port_to_netdev_data *
|
||||||
netdev_ports_lookup(odp_port_t port_no, const struct dpif_class *dpif_class)
|
netdev_ports_lookup(odp_port_t port_no, const struct dpif_class *dpif_class)
|
||||||
OVS_REQUIRES(netdev_hmap_mutex)
|
OVS_REQ_RDLOCK(netdev_hmap_rwlock)
|
||||||
{
|
{
|
||||||
struct port_to_netdev_data *data;
|
struct port_to_netdev_data *data;
|
||||||
|
|
||||||
@@ -531,9 +531,9 @@ netdev_ports_insert(struct netdev *netdev, const struct dpif_class *dpif_class,
|
|||||||
return ENODEV;
|
return ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
ovs_mutex_lock(&netdev_hmap_mutex);
|
ovs_rwlock_wrlock(&netdev_hmap_rwlock);
|
||||||
if (netdev_ports_lookup(dpif_port->port_no, dpif_class)) {
|
if (netdev_ports_lookup(dpif_port->port_no, dpif_class)) {
|
||||||
ovs_mutex_unlock(&netdev_hmap_mutex);
|
ovs_rwlock_unlock(&netdev_hmap_rwlock);
|
||||||
return EEXIST;
|
return EEXIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -546,7 +546,7 @@ netdev_ports_insert(struct netdev *netdev, const struct dpif_class *dpif_class,
|
|||||||
hmap_insert(&port_to_netdev, &data->portno_node,
|
hmap_insert(&port_to_netdev, &data->portno_node,
|
||||||
netdev_ports_hash(dpif_port->port_no, dpif_class));
|
netdev_ports_hash(dpif_port->port_no, dpif_class));
|
||||||
hmap_insert(&ifindex_to_port, &data->ifindex_node, ifindex);
|
hmap_insert(&ifindex_to_port, &data->ifindex_node, ifindex);
|
||||||
ovs_mutex_unlock(&netdev_hmap_mutex);
|
ovs_rwlock_unlock(&netdev_hmap_rwlock);
|
||||||
|
|
||||||
netdev_init_flow_api(netdev);
|
netdev_init_flow_api(netdev);
|
||||||
|
|
||||||
@@ -559,12 +559,12 @@ netdev_ports_get(odp_port_t port_no, const struct dpif_class *dpif_class)
|
|||||||
struct port_to_netdev_data *data;
|
struct port_to_netdev_data *data;
|
||||||
struct netdev *ret = NULL;
|
struct netdev *ret = NULL;
|
||||||
|
|
||||||
ovs_mutex_lock(&netdev_hmap_mutex);
|
ovs_rwlock_rdlock(&netdev_hmap_rwlock);
|
||||||
data = netdev_ports_lookup(port_no, dpif_class);
|
data = netdev_ports_lookup(port_no, dpif_class);
|
||||||
if (data) {
|
if (data) {
|
||||||
ret = netdev_ref(data->netdev);
|
ret = netdev_ref(data->netdev);
|
||||||
}
|
}
|
||||||
ovs_mutex_unlock(&netdev_hmap_mutex);
|
ovs_rwlock_unlock(&netdev_hmap_rwlock);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -575,8 +575,7 @@ netdev_ports_remove(odp_port_t port_no, const struct dpif_class *dpif_class)
|
|||||||
struct port_to_netdev_data *data;
|
struct port_to_netdev_data *data;
|
||||||
int ret = ENOENT;
|
int ret = ENOENT;
|
||||||
|
|
||||||
ovs_mutex_lock(&netdev_hmap_mutex);
|
ovs_rwlock_wrlock(&netdev_hmap_rwlock);
|
||||||
|
|
||||||
data = netdev_ports_lookup(port_no, dpif_class);
|
data = netdev_ports_lookup(port_no, dpif_class);
|
||||||
if (data) {
|
if (data) {
|
||||||
dpif_port_destroy(&data->dpif_port);
|
dpif_port_destroy(&data->dpif_port);
|
||||||
@@ -586,8 +585,7 @@ netdev_ports_remove(odp_port_t port_no, const struct dpif_class *dpif_class)
|
|||||||
free(data);
|
free(data);
|
||||||
ret = 0;
|
ret = 0;
|
||||||
}
|
}
|
||||||
|
ovs_rwlock_unlock(&netdev_hmap_rwlock);
|
||||||
ovs_mutex_unlock(&netdev_hmap_mutex);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -598,14 +596,14 @@ netdev_ifindex_to_odp_port(int ifindex)
|
|||||||
struct port_to_netdev_data *data;
|
struct port_to_netdev_data *data;
|
||||||
odp_port_t ret = 0;
|
odp_port_t ret = 0;
|
||||||
|
|
||||||
ovs_mutex_lock(&netdev_hmap_mutex);
|
ovs_rwlock_rdlock(&netdev_hmap_rwlock);
|
||||||
HMAP_FOR_EACH_WITH_HASH (data, ifindex_node, ifindex, &ifindex_to_port) {
|
HMAP_FOR_EACH_WITH_HASH (data, ifindex_node, ifindex, &ifindex_to_port) {
|
||||||
if (data->ifindex == ifindex) {
|
if (data->ifindex == ifindex) {
|
||||||
ret = data->dpif_port.port_no;
|
ret = data->dpif_port.port_no;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ovs_mutex_unlock(&netdev_hmap_mutex);
|
ovs_rwlock_unlock(&netdev_hmap_rwlock);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -623,11 +621,11 @@ netdev_ports_flow_init(void)
|
|||||||
{
|
{
|
||||||
struct port_to_netdev_data *data;
|
struct port_to_netdev_data *data;
|
||||||
|
|
||||||
ovs_mutex_lock(&netdev_hmap_mutex);
|
ovs_rwlock_rdlock(&netdev_hmap_rwlock);
|
||||||
HMAP_FOR_EACH (data, portno_node, &port_to_netdev) {
|
HMAP_FOR_EACH (data, portno_node, &port_to_netdev) {
|
||||||
netdev_init_flow_api(data->netdev);
|
netdev_init_flow_api(data->netdev);
|
||||||
}
|
}
|
||||||
ovs_mutex_unlock(&netdev_hmap_mutex);
|
ovs_rwlock_unlock(&netdev_hmap_rwlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Reference in New Issue
Block a user