#include "netlink.h"
#include "odp-util.h"
#include "ofpbuf.h"
-#include "openvswitch/datapath-compat.h"
#include "packets.h"
#include "poll-loop.h"
#include "random.h"
/* Attributes. */
const char *name; /* OVS_DP_ATTR_NAME. */
- const uint32_t *upcall_pid; /* OVS_DP_UPCALL_PID. */
+ const uint32_t *upcall_pid; /* OVS_DP_ATTR_UPCALL_PID. */
struct ovs_dp_stats stats; /* OVS_DP_ATTR_STATS. */
+ struct ovs_dp_megaflow_stats megaflow_stats;
+ /* OVS_DP_ATTR_MEGAFLOW_STATS.*/
};
static void dpif_linux_dp_init(struct dpif_linux_dp *);
int dp_ifindex;
/* Upcall messages. */
+ struct ovs_mutex upcall_lock;
int uc_array_size; /* Size of 'channels' and 'epoll_events'. */
struct dpif_channel *channels;
struct epoll_event *epoll_events;
dpif = xzalloc(sizeof *dpif);
dpif->port_notifier = NULL;
+ ovs_mutex_init(&dpif->upcall_lock);
dpif->epoll_fd = -1;
dpif_init(&dpif->dpif, &dpif_linux_class, dp->name,
continue;
}
+ epoll_ctl(dpif->epoll_fd, EPOLL_CTL_DEL, nl_sock_fd(ch->sock), NULL);
+
/* Turn off upcalls. */
dpif_linux_vport_init(&vport_request);
vport_request.cmd = OVS_VPORT_CMD_SET;
dpif->epoll_events = NULL;
dpif->n_events = dpif->event_offset = 0;
- close(dpif->epoll_fd);
- dpif->epoll_fd = -1;
+ /* Don't close dpif->epoll_fd since that would cause other threads that
+ * call dpif_recv_wait(dpif) to wait on an arbitrary fd or a closed fd. */
}
static int
nl_sock_destroy(dpif->port_notifier);
destroy_channels(dpif);
+ if (dpif->epoll_fd >= 0) {
+ close(dpif->epoll_fd);
+ }
+ ovs_mutex_destroy(&dpif->upcall_lock);
free(dpif);
}
stats->n_missed = dp.stats.n_missed;
stats->n_lost = dp.stats.n_lost;
stats->n_flows = dp.stats.n_flows;
+ stats->n_masks = dp.megaflow_stats.n_masks;
+ stats->n_mask_hit = dp.megaflow_stats.n_mask_hit;
ofpbuf_delete(buf);
}
return error;
}
static int
-dpif_linux_port_add(struct dpif *dpif_, struct netdev *netdev,
- odp_port_t *port_nop)
+dpif_linux_port_add__(struct dpif *dpif_, struct netdev *netdev,
+ odp_port_t *port_nop)
{
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
const struct netdev_tunnel_config *tnl_cfg;
}
static int
-dpif_linux_port_del(struct dpif *dpif_, odp_port_t port_no)
+dpif_linux_port_add(struct dpif *dpif_, struct netdev *netdev,
+ odp_port_t *port_nop)
+{
+ struct dpif_linux *dpif = dpif_linux_cast(dpif_);
+ int error;
+
+ ovs_mutex_lock(&dpif->upcall_lock);
+ error = dpif_linux_port_add__(dpif_, netdev, port_nop);
+ ovs_mutex_unlock(&dpif->upcall_lock);
+
+ return error;
+}
+
+static int
+dpif_linux_port_del__(struct dpif *dpif_, odp_port_t port_no)
{
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
struct dpif_linux_vport vport;
return error;
}
+static int
+dpif_linux_port_del(struct dpif *dpif_, odp_port_t port_no)
+{
+ struct dpif_linux *dpif = dpif_linux_cast(dpif_);
+ int error;
+
+ ovs_mutex_lock(&dpif->upcall_lock);
+ error = dpif_linux_port_del__(dpif_, port_no);
+ ovs_mutex_unlock(&dpif->upcall_lock);
+
+ return error;
+}
+
static int
dpif_linux_port_query__(const struct dpif *dpif, odp_port_t port_no,
const char *port_name, struct dpif_port *dpif_port)
return dpif_linux_port_query__(dpif, 0, devname, dpif_port);
}
-static odp_port_t
+static uint32_t
dpif_linux_get_max_ports(const struct dpif *dpif OVS_UNUSED)
{
- return u32_to_odp(MAX_PORTS);
+ return MAX_PORTS;
}
static uint32_t
dpif_linux_port_get_pid(const struct dpif *dpif_, odp_port_t port_no)
{
- const struct dpif_linux *dpif = dpif_linux_cast(dpif_);
+ struct dpif_linux *dpif = dpif_linux_cast(dpif_);
uint32_t port_idx = odp_to_u32(port_no);
+ uint32_t pid = 0;
- if (dpif->epoll_fd < 0) {
- return 0;
- } else {
+ ovs_mutex_lock(&dpif->upcall_lock);
+ if (dpif->epoll_fd >= 0) {
/* The ODPP_NONE "reserved" port number uses the "ovs-system"'s
* channel, since it is not heavily loaded. */
uint32_t idx = port_idx >= dpif->uc_array_size ? 0 : port_idx;
- return nl_sock_pid(dpif->channels[idx].sock);
+ pid = nl_sock_pid(dpif->channels[idx].sock);
}
+ ovs_mutex_unlock(&dpif->upcall_lock);
+
+ return pid;
}
static int
*statep = state = xmalloc(sizeof *state);
dpif_linux_vport_init(&request);
- request.cmd = OVS_DP_CMD_GET;
+ request.cmd = OVS_VPORT_CMD_GET;
request.dp_ifindex = dpif->dp_ifindex;
buf = ofpbuf_new(1024);
VLOG_DBG("port_changed: dpif:%s vport:%s cmd:%"PRIu8,
dpif->dpif.full_name, vport.name, vport.cmd);
*devnamep = xstrdup(vport.name);
+ ofpbuf_uninit(&buf);
return 0;
- } else {
- continue;
}
}
- } else if (error == EAGAIN) {
- return EAGAIN;
+ } else if (error != EAGAIN) {
+ VLOG_WARN_RL(&rl, "error reading or parsing netlink (%s)",
+ ovs_strerror(error));
+ nl_sock_drain(dpif->port_notifier);
+ error = ENOBUFS;
}
- VLOG_WARN_RL(&rl, "error reading or parsing netlink (%s)",
- ovs_strerror(error));
- nl_sock_drain(dpif->port_notifier);
- return ENOBUFS;
+ ofpbuf_uninit(&buf);
+ if (error) {
+ return error;
+ }
}
}
*statep = state = xmalloc(sizeof *state);
dpif_linux_flow_init(&request);
- request.cmd = OVS_DP_CMD_GET;
+ request.cmd = OVS_FLOW_CMD_GET;
request.dp_ifindex = dpif->dp_ifindex;
buf = ofpbuf_new(1024);
}
static int
-dpif_linux_recv_set(struct dpif *dpif_, bool enable)
+dpif_linux_recv_set__(struct dpif *dpif_, bool enable)
{
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
struct dpif_port_dump port_dump;
struct dpif_port port;
- dpif->epoll_fd = epoll_create(10);
if (dpif->epoll_fd < 0) {
- return errno;
+ dpif->epoll_fd = epoll_create(10);
+ if (dpif->epoll_fd < 0) {
+ return errno;
+ }
}
DPIF_PORT_FOR_EACH (&port, &port_dump, &dpif->dpif) {
return 0;
}
+static int
+dpif_linux_recv_set(struct dpif *dpif_, bool enable)
+{
+ struct dpif_linux *dpif = dpif_linux_cast(dpif_);
+ int error;
+
+ ovs_mutex_lock(&dpif->upcall_lock);
+ error = dpif_linux_recv_set__(dpif_, enable);
+ ovs_mutex_unlock(&dpif->upcall_lock);
+
+ return error;
+}
+
static int
dpif_linux_queue_to_priority(const struct dpif *dpif OVS_UNUSED,
uint32_t queue_id, uint32_t *priority)
}
static int
-dpif_linux_recv(struct dpif *dpif_, struct dpif_upcall *upcall,
- struct ofpbuf *buf)
+dpif_linux_recv__(struct dpif *dpif_, struct dpif_upcall *upcall,
+ struct ofpbuf *buf)
{
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
int read_tries = 0;
return EAGAIN;
}
+static int
+dpif_linux_recv(struct dpif *dpif_, struct dpif_upcall *upcall,
+ struct ofpbuf *buf)
+{
+ struct dpif_linux *dpif = dpif_linux_cast(dpif_);
+ int error;
+
+ ovs_mutex_lock(&dpif->upcall_lock);
+ error = dpif_linux_recv__(dpif_, upcall, buf);
+ ovs_mutex_unlock(&dpif->upcall_lock);
+
+ return error;
+}
+
static void
dpif_linux_recv_wait(struct dpif *dpif_)
{
- const struct dpif_linux *dpif = dpif_linux_cast(dpif_);
+ struct dpif_linux *dpif = dpif_linux_cast(dpif_);
- if (dpif->epoll_fd < 0) {
- return;
+ ovs_mutex_lock(&dpif->upcall_lock);
+ if (dpif->epoll_fd >= 0) {
+ poll_fd_wait(dpif->epoll_fd, POLLIN);
}
-
- poll_fd_wait(dpif->epoll_fd, POLLIN);
+ ovs_mutex_unlock(&dpif->upcall_lock);
}
static void
dpif_linux_recv_purge(struct dpif *dpif_)
{
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
- struct dpif_channel *ch;
- if (dpif->epoll_fd < 0) {
- return;
- }
+ ovs_mutex_lock(&dpif->upcall_lock);
+ if (dpif->epoll_fd >= 0) {
+ struct dpif_channel *ch;
- for (ch = dpif->channels; ch < &dpif->channels[dpif->uc_array_size]; ch++) {
- if (ch->sock) {
- nl_sock_drain(ch->sock);
+ for (ch = dpif->channels; ch < &dpif->channels[dpif->uc_array_size];
+ ch++) {
+ if (ch->sock) {
+ nl_sock_drain(ch->sock);
+ }
}
}
+ ovs_mutex_unlock(&dpif->upcall_lock);
}
const struct dpif_class dpif_linux_class = {
}
if (!error) {
error = nl_lookup_genl_mcgroup(OVS_VPORT_FAMILY, OVS_VPORT_MCGROUP,
- &ovs_vport_mcgroup,
- OVS_VPORT_MCGROUP_FALLBACK_ID);
+ &ovs_vport_mcgroup);
}
ovsthread_once_done(&once);
[OVS_DP_ATTR_NAME] = { .type = NL_A_STRING, .max_len = IFNAMSIZ },
[OVS_DP_ATTR_STATS] = { NL_POLICY_FOR(struct ovs_dp_stats),
.optional = true },
+ [OVS_DP_ATTR_MEGAFLOW_STATS] = {
+ NL_POLICY_FOR(struct ovs_dp_megaflow_stats),
+ .optional = true },
};
struct nlattr *a[ARRAY_SIZE(ovs_datapath_policy)];
sizeof dp->stats);
}
+ if (a[OVS_DP_ATTR_MEGAFLOW_STATS]) {
+ /* Can't use structure assignment because Netlink doesn't ensure
+ * sufficient alignment for 64-bit members. */
+ memcpy(&dp->megaflow_stats, nl_attr_get(a[OVS_DP_ATTR_MEGAFLOW_STATS]),
+ sizeof dp->megaflow_stats);
+ }
+
return 0;
}
dpif_linux_dp_init(struct dpif_linux_dp *dp)
{
memset(dp, 0, sizeof *dp);
+ dp->megaflow_stats.n_masks = UINT32_MAX;
+ dp->megaflow_stats.n_mask_hit = UINT64_MAX;
}
static void
ofpbuf_delete(request_buf);
if (reply) {
+ dpif_linux_dp_init(reply);
if (!error) {
error = dpif_linux_dp_from_ofpbuf(reply, *bufp);
}
if (error) {
- dpif_linux_dp_init(reply);
ofpbuf_delete(*bufp);
*bufp = NULL;
}