This patch refactors dp_netdev_flow_offload_put() to prepare for changes to support partial action offload, in subsequent patches.
- Move mark allocation code into a separate wrapper function, outside of dp_netdev_flow_offload_put() to improve readability and to facilitate more changes in this function to support partial action offload. - We need to get the in-port's netdev-type (e.g, vhost) to determine if the flow should be offloaded on the egress device instead. To facilitate such changes, netdev_ports_get() is moved ahead of mark allocation. Signed-off-by: Sriharsha Basavapatna <sriharsha.basavapa...@broadcom.com> --- lib/dpif-netdev.c | 71 ++++++++++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 26 deletions(-) diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index ea7b187b2..781b233f4 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -2357,6 +2357,43 @@ dp_netdev_flow_offload_del(struct dp_flow_offload_item *offload) return mark_to_flow_disassociate(offload->pmd, offload->flow); } +static int +dp_netdev_alloc_flow_mark(struct dp_netdev_flow *flow, bool modification, + uint32_t *markp) +{ + uint32_t mark; + + if (modification) { + mark = flow->mark; + ovs_assert(mark != INVALID_FLOW_MARK); + *markp = mark; + return 0; + } + + /* + * If a mega flow has already been offloaded (from other PMD + * instances), do not offload it again. + */ + mark = megaflow_to_mark_find(&flow->mega_ufid); + if (mark != INVALID_FLOW_MARK) { + VLOG_DBG("Flow has already been offloaded with mark %u\n", mark); + if (flow->mark != INVALID_FLOW_MARK) { + ovs_assert(flow->mark == mark); + } else { + mark_to_flow_associate(mark, flow); + } + return 1; + } + + mark = netdev_offload_flow_mark_alloc(); + if (mark == INVALID_FLOW_MARK) { + VLOG_ERR("Failed to allocate flow mark!\n"); + } + + *markp = mark; + return 0; +} + /* * There are two flow offload operations here: addition and modification. * @@ -2385,36 +2422,18 @@ dp_netdev_flow_offload_put(struct dp_flow_offload_item *offload) return -1; } - if (modification) { - mark = flow->mark; - ovs_assert(mark != INVALID_FLOW_MARK); - } else { - /* - * If a mega flow has already been offloaded (from other PMD - * instances), do not offload it again. - */ - mark = megaflow_to_mark_find(&flow->mega_ufid); - if (mark != INVALID_FLOW_MARK) { - VLOG_DBG("Flow has already been offloaded with mark %u\n", mark); - if (flow->mark != INVALID_FLOW_MARK) { - ovs_assert(flow->mark == mark); - } else { - mark_to_flow_associate(mark, flow); - } - return 0; - } + port = netdev_ports_get(in_port, dpif_type_str); + if (!port) { + return -1; + } - mark = netdev_offload_flow_mark_alloc(); - if (mark == INVALID_FLOW_MARK) { - VLOG_ERR("Failed to allocate flow mark!\n"); - } + if (dp_netdev_alloc_flow_mark(flow, modification, &mark)) { + /* flow already offloaded */ + netdev_close(port); + return 0; } info.flow_mark = mark; - port = netdev_ports_get(in_port, dpif_type_str); - if (!port) { - goto err_free; - } /* Taking a global 'port_mutex' to fulfill thread safety restrictions for * the netdev-offload-dpdk module. */ ovs_mutex_lock(&pmd->dp->port_mutex); -- 2.25.0.rc2 _______________________________________________ dev mailing list d...@openvswitch.org https://mail.openvswitch.org/mailman/listinfo/ovs-dev