diff mbox series

[ovs-dev,01/14] northd: Find ovn_datapath from a single hmap.

Message ID 20250609173539.1636916-2-mmichels@redhat.com
State Deferred
Headers show
Series Logical Flow Sync Refactor. | expand

Checks

Context Check Description
ovsrobot/apply-robot fail apply and check: fail

Commit Message

Mark Michelson June 9, 2025, 5:35 p.m. UTC
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. This works because
in the previous commit, we changed the southbound external_ids key to be
consistent across datapath types.

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 <mmichels@redhat.com>
---
 northd/en-learned-route-sync.c |  8 +++----
 northd/en-multicast.c          |  3 +--
 northd/northd.c                | 41 +++++++++++++++++++++-------------
 northd/northd.h                |  3 +++
 4 files changed, 33 insertions(+), 22 deletions(-)
diff mbox series

Patch

diff --git a/northd/en-learned-route-sync.c b/northd/en-learned-route-sync.c
index f14f610ac..1e51dec40 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;
@@ -236,8 +236,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 d51db557e..504ff0f1b 100644
--- a/northd/en-multicast.c
+++ b/northd/en-multicast.c
@@ -273,8 +273,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 7f882df18..5efadd3f7 100644
--- a/northd/northd.c
+++ b/northd/northd.c
@@ -577,12 +577,30 @@  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 (!uuid_from_string(&key, sb->nb_uuid)) {
+        /* This was inserted by something other than ovn-northd. */
+        return NULL;
+    }
+
+    struct ovn_datapath *od = ovn_datapath_find_(datapaths, &key);
+    if (od && (od->sb == sb)) {
+        return od;
+    }
+
+    return NULL;
+}
+
 struct ovn_datapath *
 ovn_datapath_from_sbrec(const struct hmap *ls_datapaths,
                         const struct hmap *lr_datapaths,
                         const struct sbrec_datapath_binding *sb)
 {
-    struct uuid key;
     const struct hmap *dps;
 
     if (!strcmp(sb->type, "logical-switch")) {
@@ -593,15 +611,7 @@  ovn_datapath_from_sbrec(const struct hmap *ls_datapaths,
         return NULL;
     }
 
-    if (!uuid_from_string(&key, sb->nb_uuid)) {
-        return NULL;
-    }
-    struct ovn_datapath *od = ovn_datapath_find_(dps, &key);
-    if (od && (od->sb == sb)) {
-        return od;
-    }
-
-    return NULL;
+    return ovn_datapath_from_sbrec_(dps, sb);
 }
 
 static bool
@@ -2027,8 +2037,7 @@  join_logical_ports(
     struct shash_node *node;
     SHASH_FOR_EACH (node, &paired_lrps->paired_router_ports) {
         struct ovn_paired_logical_router_port *slrp = node->data;
-        od = ovn_datapath_from_sbrec(ls_datapaths, lr_datapaths,
-                                     slrp->router->sb);
+        od = ovn_datapath_from_sbrec_(lr_datapaths, slrp->router->sb);
         if (!od) {
             /* This can happen if the router is not enabled */
             continue;
@@ -2047,10 +2056,10 @@  join_logical_ports(
 
     SHASH_FOR_EACH (node, &paired_lsps->paired_switch_ports) {
         struct ovn_paired_logical_switch_port *slsp = node->data;
-        od = ovn_datapath_from_sbrec(ls_datapaths, lr_datapaths,
-                                     slsp->sw->sb);
+        od = ovn_datapath_from_sbrec_(ls_datapaths, slsp->sw->sb);
 
         ovs_assert(od);
+
         join_logical_ports_lsp(ls_ports, od, slsp->nb, slsp->sb,
                                slsp->nb->name, queue_id_bitmap,
                                tag_alloc_table);
@@ -3133,7 +3142,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)) {
@@ -18456,7 +18465,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 3a7198616..21c068f35 100644
--- a/northd/northd.h
+++ b/northd/northd.h
@@ -445,6 +445,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)
 {