The ovn_datapath_from_sbrec() function requires two hmaps to be passed
in. It needs the hmap of logical_switches and the hmap of
logical_routers.

In many cases, there is only a single northbound type that we care to
try to find. In this commit, we add a new version of
ovn_datapath_from_sbrec() that takes a single hmap.

Since there are several places in the code that passed NULL as one of
the hmap arguments to ovn_datapath_from_sbrec(), these have been
converted to use ovn_datapath_from_sbrec_() instead.

Signed-off-by: Mark Michelson <[email protected]>
---
 northd/en-learned-route-sync.c |  8 ++++----
 northd/en-multicast.c          |  3 +--
 northd/northd.c                | 22 ++++++++++++++++++++--
 northd/northd.h                |  3 +++
 4 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/northd/en-learned-route-sync.c b/northd/en-learned-route-sync.c
index f22aaa664..acefaef38 100644
--- a/northd/en-learned-route-sync.c
+++ b/northd/en-learned-route-sync.c
@@ -149,8 +149,8 @@ parse_route_from_sbrec_route(struct hmap *parsed_routes_out,
                              const struct hmap *lr_datapaths,
                              const struct sbrec_learned_route *route)
 {
-    const struct ovn_datapath *od = ovn_datapath_from_sbrec(
-        NULL, lr_datapaths, route->datapath);
+    const struct ovn_datapath *od = ovn_datapath_from_sbrec_(
+        lr_datapaths, route->datapath);
 
     if (!od || ovn_datapath_is_stale(od)) {
         return NULL;
@@ -239,8 +239,8 @@ find_learned_route(const struct sbrec_learned_route 
*learned_route,
                    const struct ovn_datapaths *lr_datapaths,
                    const struct hmap *routes)
 {
-    const struct ovn_datapath *od = ovn_datapath_from_sbrec(
-        NULL, &lr_datapaths->datapaths, learned_route->datapath);
+    const struct ovn_datapath *od = ovn_datapath_from_sbrec_(
+        &lr_datapaths->datapaths, learned_route->datapath);
     if (!od) {
         return NULL;
     }
diff --git a/northd/en-multicast.c b/northd/en-multicast.c
index f63825c8d..a7dfd71c4 100644
--- a/northd/en-multicast.c
+++ b/northd/en-multicast.c
@@ -277,8 +277,7 @@ build_mcast_groups(struct multicast_igmp_data *data,
         }
 
         /* If the datapath value is stale, purge the group. */
-        od = ovn_datapath_from_sbrec(ls_datapaths, NULL,
-                                     sb_igmp->datapath);
+        od = ovn_datapath_from_sbrec_(ls_datapaths, sb_igmp->datapath);
 
         if (!od || ovn_datapath_is_stale(od)) {
             sbrec_igmp_group_delete(sb_igmp);
diff --git a/northd/northd.c b/northd/northd.c
index c3c0780a3..686bb28f0 100644
--- a/northd/northd.c
+++ b/northd/northd.c
@@ -627,6 +627,24 @@ ovn_datapath_find_by_key(struct hmap *datapaths, uint32_t 
dp_key)
     return NULL;
 }
 
+struct ovn_datapath *
+ovn_datapath_from_sbrec_(const struct hmap *datapaths,
+                         const struct sbrec_datapath_binding *sb)
+{
+    struct uuid key;
+
+    if (!datapath_get_nb_uuid(sb, &key)) {
+        return NULL;
+    }
+
+    struct ovn_datapath *od = ovn_datapath_find_(datapaths, &key);
+    if (od && (od->sdp->sb_dp == sb)) {
+        return od;
+    }
+
+    return NULL;
+}
+
 struct ovn_datapath *
 ovn_datapath_from_sbrec(const struct hmap *ls_datapaths,
                         const struct hmap *lr_datapaths,
@@ -2946,7 +2964,7 @@ cleanup_mac_bindings(
     const struct sbrec_mac_binding *b;
     SBREC_MAC_BINDING_TABLE_FOR_EACH_SAFE (b, sbrec_mac_binding_table) {
         const struct ovn_datapath *od =
-            ovn_datapath_from_sbrec(NULL, lr_datapaths, b->datapath);
+            ovn_datapath_from_sbrec_(lr_datapaths, b->datapath);
 
         if (!od || ovn_datapath_is_stale(od) ||
             !ovn_port_find(lr_ports, b->logical_port)) {
@@ -20133,7 +20151,7 @@ build_ip_mcast(struct ovsdb_idl_txn *ovnsb_txn,
     const struct sbrec_ip_multicast *sb;
 
     SBREC_IP_MULTICAST_TABLE_FOR_EACH_SAFE (sb, sbrec_ip_multicast_table) {
-        od = ovn_datapath_from_sbrec(ls_datapaths, NULL, sb->datapath);
+        od = ovn_datapath_from_sbrec_(ls_datapaths, sb->datapath);
         if (!od || ovn_datapath_is_stale(od)) {
             sbrec_ip_multicast_delete(sb);
         }
diff --git a/northd/northd.h b/northd/northd.h
index 2869ea97e..94950b822 100644
--- a/northd/northd.h
+++ b/northd/northd.h
@@ -501,6 +501,9 @@ struct ovn_datapath *ovn_datapath_from_sbrec(
     const struct hmap *ls_datapaths, const struct hmap *lr_datapaths,
     const struct sbrec_datapath_binding *);
 
+struct ovn_datapath *ovn_datapath_from_sbrec_(
+    const struct hmap *datapaths, const struct sbrec_datapath_binding *);
+
 static inline bool
 ovn_datapath_is_stale(const struct ovn_datapath *od)
 {
-- 
2.51.1

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to