[ovs-dev] [PATCH v3 2/6] netdev-provider: add class op to get block_id

John Hurley john.hurley at netronome.com
Thu Jun 28 16:03:03 UTC 2018


Add a new class op for netdevs to get the block_id if one exists. The
block_id is used in offload ops to group multiple qdiscs together.

Stub calls are made to the new class op (implementation to follow in
further patches). The default block_id of 0 (no block) will be used in
these cases.

Signed-off-by: John Hurley <john.hurley at netronome.com>
Reviewed-by: Dirk van der Merwe <dirk.vandermerwe at netronome.com>
Reviewed-by: Simon Horman <simon.horman at netronome.com>
Signed-off-by: Jakub Kicinski <jakub.kicinski at netronome.com>
---
 lib/netdev-bsd.c         |  3 ++-
 lib/netdev-dpdk.c        |  3 ++-
 lib/netdev-dummy.c       |  3 ++-
 lib/netdev-linux.c       |  3 ++-
 lib/netdev-provider.h    |  4 ++++
 lib/netdev-tc-offloads.c | 18 ++++++++++++++++++
 lib/netdev-vport.c       |  3 ++-
 lib/netdev.c             | 10 ++++++++++
 lib/netdev.h             |  1 +
 9 files changed, 43 insertions(+), 5 deletions(-)

diff --git a/lib/netdev-bsd.c b/lib/netdev-bsd.c
index b70f327..c6946f9 100644
--- a/lib/netdev-bsd.c
+++ b/lib/netdev-bsd.c
@@ -1553,7 +1553,8 @@ netdev_bsd_update_flags(struct netdev *netdev_, enum netdev_flags off,
     netdev_bsd_rxq_wait,                             \
     netdev_bsd_rxq_drain,                            \
                                                      \
-    NO_OFFLOAD_API                                   \
+    NO_OFFLOAD_API,                                  \
+    NULL /* get_block_id */   \
 }
 
 const struct netdev_class netdev_bsd_class =
diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c
index 1bde9cf..c223e5b 100644
--- a/lib/netdev-dpdk.c
+++ b/lib/netdev-dpdk.c
@@ -3957,7 +3957,8 @@ unlock:
     RXQ_RECV,                                                 \
     NULL,                       /* rx_wait */                 \
     NULL,                       /* rxq_drain */               \
-    NO_OFFLOAD_API                                            \
+    NO_OFFLOAD_API,                                           \
+    NULL                        /* get_block_id */            \
 }
 
 static const struct netdev_class dpdk_class =
diff --git a/lib/netdev-dummy.c b/lib/netdev-dummy.c
index fbc98dd..d498467 100644
--- a/lib/netdev-dummy.c
+++ b/lib/netdev-dummy.c
@@ -1464,7 +1464,8 @@ netdev_dummy_update_flags(struct netdev *netdev_,
     netdev_dummy_rxq_wait,                                      \
     netdev_dummy_rxq_drain,                                     \
                                                                 \
-    NO_OFFLOAD_API                                              \
+    NO_OFFLOAD_API,                                             \
+    NULL                        /* get_block_id */              \
 }
 
 static const struct netdev_class dummy_class =
diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c
index d89a0fb..8feab98 100644
--- a/lib/netdev-linux.c
+++ b/lib/netdev-linux.c
@@ -3115,7 +3115,8 @@ exit:
     netdev_linux_rxq_wait,                                      \
     netdev_linux_rxq_drain,                                     \
                                                                 \
-    FLOW_OFFLOAD_API                                            \
+    FLOW_OFFLOAD_API,                                           \
+    NULL                        /* get_block_id */              \
 }
 
 const struct netdev_class netdev_linux_class =
diff --git a/lib/netdev-provider.h b/lib/netdev-provider.h
index 4da579c..1a572f5 100644
--- a/lib/netdev-provider.h
+++ b/lib/netdev-provider.h
@@ -870,6 +870,10 @@ struct netdev_class {
     /* Initializies the netdev flow api.
      * Return 0 if successful, otherwise returns a positive errno value. */
     int (*init_flow_api)(struct netdev *);
+
+    /* Get a block_id from the netdev.
+     * Returns the block_id or 0 if none exists for netdev. */
+    uint32_t (*get_block_id)(struct netdev *);
 };
 
 int netdev_register_provider(const struct netdev_class *);
diff --git a/lib/netdev-tc-offloads.c b/lib/netdev-tc-offloads.c
index 14558ad..86dbeec 100644
--- a/lib/netdev-tc-offloads.c
+++ b/lib/netdev-tc-offloads.c
@@ -304,6 +304,16 @@ get_prio_for_tc_flower(struct tc_flower *flower)
     return new_data->prio;
 }
 
+static uint32_t
+get_block_id_from_netdev(struct netdev *netdev)
+{
+    if (block_support) {
+        return netdev_get_block_id(netdev);
+    }
+
+    return 0;
+}
+
 int
 netdev_tc_flow_flush(struct netdev *netdev)
 {
@@ -316,6 +326,8 @@ netdev_tc_flow_flush(struct netdev *netdev)
         return -ifindex;
     }
 
+    block_id = get_block_id_from_netdev(netdev);
+
     return tc_flush(ifindex, block_id);
 }
 
@@ -334,6 +346,7 @@ netdev_tc_flow_dump_create(struct netdev *netdev,
         return -ifindex;
     }
 
+    block_id = get_block_id_from_netdev(netdev);
     dump = xzalloc(sizeof *dump);
     dump->nl_dump = xzalloc(sizeof *dump->nl_dump);
     dump->netdev = netdev_ref(netdev);
@@ -1098,6 +1111,7 @@ netdev_tc_flow_put(struct netdev *netdev, struct match *match,
         }
     }
 
+    block_id = get_block_id_from_netdev(netdev);
     handle = get_ufid_tc_mapping(ufid, &prio, NULL);
     if (handle && prio) {
         VLOG_DBG_RL(&rl, "updating old handle: %d prio: %d", handle, prio);
@@ -1157,6 +1171,7 @@ netdev_tc_flow_get(struct netdev *netdev OVS_UNUSED,
 
     VLOG_DBG_RL(&rl, "flow get (dev %s prio %d handle %d)",
                 netdev_get_name(dev), prio, handle);
+    block_id = get_block_id_from_netdev(netdev);
     err = tc_get_flower(ifindex, prio, handle, &flower, block_id);
     netdev_close(dev);
     if (err) {
@@ -1200,6 +1215,8 @@ netdev_tc_flow_del(struct netdev *netdev OVS_UNUSED,
         return -ifindex;
     }
 
+    block_id = get_block_id_from_netdev(netdev);
+
     if (stats) {
         memset(stats, 0, sizeof *stats);
         if (!tc_get_flower(ifindex, prio, handle, &flower, block_id)) {
@@ -1289,6 +1306,7 @@ netdev_tc_init_flow_api(struct netdev *netdev)
         ovsthread_once_done(&block_once);
     }
 
+    block_id = get_block_id_from_netdev(netdev);
     error = tc_add_del_ingress_qdisc(ifindex, true, block_id);
 
     if (error && error != EEXIST) {
diff --git a/lib/netdev-vport.c b/lib/netdev-vport.c
index 1dae7e0..2290de9 100644
--- a/lib/netdev-vport.c
+++ b/lib/netdev-vport.c
@@ -1050,7 +1050,8 @@ netdev_vport_get_ifindex(const struct netdev *netdev_)
     NULL,                   /* rx_wait */                   \
     NULL,                   /* rx_drain */                  \
                                                             \
-    NETDEV_FLOW_OFFLOAD_API
+    NETDEV_FLOW_OFFLOAD_API,                                 \
+    NULL                    /* get_block_id */
 
 
 #define TUNNEL_CLASS(NAME, DPIF_PORT, BUILD_HEADER, PUSH_HEADER, POP_HEADER,   \
diff --git a/lib/netdev.c b/lib/netdev.c
index 83614f5..82ffeb9 100644
--- a/lib/netdev.c
+++ b/lib/netdev.c
@@ -2225,6 +2225,16 @@ netdev_init_flow_api(struct netdev *netdev)
             : EOPNOTSUPP);
 }
 
+uint32_t
+netdev_get_block_id(struct netdev *netdev)
+{
+    const struct netdev_class *class = netdev->netdev_class;
+
+    return (class->get_block_id
+            ? class->get_block_id(netdev)
+            : 0);
+}
+
 bool
 netdev_is_flow_api_enabled(void)
 {
diff --git a/lib/netdev.h b/lib/netdev.h
index 490b346..c941f1e 100644
--- a/lib/netdev.h
+++ b/lib/netdev.h
@@ -220,6 +220,7 @@ int netdev_flow_get(struct netdev *, struct match *, struct nlattr **actions,
 int netdev_flow_del(struct netdev *, const ovs_u128 *,
                     struct dpif_flow_stats *);
 int netdev_init_flow_api(struct netdev *);
+uint32_t netdev_get_block_id(struct netdev *);
 bool netdev_is_flow_api_enabled(void);
 void netdev_set_flow_api_enabled(const struct smap *ovs_other_config);
 
-- 
2.7.4



More information about the dev mailing list