This is required to add I-P for logical switch and logical router
inserts.

Signed-off-by: Lorenzo Bianconi <lorenzo.bianc...@redhat.com>
---
 northd/lb.c        |  2 +-
 northd/lb.h        |  1 +
 northd/lflow-mgr.c |  8 +++++---
 northd/northd.c    | 49 ++++++++++++++++++++++++++++------------------
 northd/northd.h    |  6 ++++--
 5 files changed, 41 insertions(+), 25 deletions(-)

diff --git a/northd/lb.c b/northd/lb.c
index 11bd17515..039830563 100644
--- a/northd/lb.c
+++ b/northd/lb.c
@@ -650,7 +650,7 @@ ovn_lb_datapaths_destroy(struct ovn_lb_datapaths *lb_dps)
     free(lb_dps);
 }
 
-static void
+void
 dynamic_bitmap_realloc(struct dynamic_bitmap *db, size_t new_n_elems)
 {
     if (new_n_elems > db->capacity) {
diff --git a/northd/lb.h b/northd/lb.h
index 81cb59fec..885d1afc4 100644
--- a/northd/lb.h
+++ b/northd/lb.h
@@ -189,6 +189,7 @@ struct ovn_lb_datapaths *ovn_lb_datapaths_create(const 
struct ovn_northd_lb *,
 struct ovn_lb_datapaths *ovn_lb_datapaths_find(const struct hmap *,
                                                const struct uuid *);
 void ovn_lb_datapaths_destroy(struct ovn_lb_datapaths *);
+void dynamic_bitmap_realloc(struct dynamic_bitmap *, size_t new_n_elems);
 
 void ovn_lb_datapaths_add_lr(struct ovn_lb_datapaths *, size_t n,
                              struct ovn_datapath **,
diff --git a/northd/lflow-mgr.c b/northd/lflow-mgr.c
index 31476286a..6a66a9718 100644
--- a/northd/lflow-mgr.c
+++ b/northd/lflow-mgr.c
@@ -1007,12 +1007,12 @@ sync_lflow_to_sb(struct ovn_lflow *lflow,
 
     if (ovn_stage_to_datapath_type(lflow->stage) == DP_SWITCH) {
         n_datapaths = ods_size(ls_datapaths);
-        datapaths_array = ls_datapaths->array;
+        datapaths_array = vector_get_array(&ls_datapaths->dps);
         dp_groups = &lflow_table->ls_dp_groups;
         is_switch = true;
     } else {
         n_datapaths = ods_size(lr_datapaths);
-        datapaths_array = lr_datapaths->array;
+        datapaths_array = vector_get_array(&lr_datapaths->dps);
         dp_groups = &lflow_table->lr_dp_groups;
         is_switch = false;
     }
@@ -1226,7 +1226,9 @@ ovn_sb_insert_or_update_logical_dp_group(
 
     sb = xmalloc(bitmap_count1(dpg_bitmap, ods_size(datapaths)) * sizeof *sb);
     BITMAP_FOR_EACH_1 (index, ods_size(datapaths), dpg_bitmap) {
-        sb[n++] = datapaths->array[index]->sdp->sb_dp;
+        struct ovn_datapath *od = vector_get(&datapaths->dps, index,
+                                             struct ovn_datapath *);
+        sb[n++] = od->sdp->sb_dp;
     }
     if (!dp_group) {
         struct uuid dpg_uuid = uuid_random();
diff --git a/northd/northd.c b/northd/northd.c
index 0de440559..7cbea7d57 100644
--- a/northd/northd.c
+++ b/northd/northd.c
@@ -839,18 +839,22 @@ parse_dynamic_routing_redistribute(
 static void
 ods_build_array_index(struct ovn_datapaths *datapaths)
 {
+    datapaths->dps = VECTOR_CAPACITY_INITIALIZER(struct ovn_datapath *,
+                                                 ods_size(datapaths));
+    datapaths->dps_index_map.map = bitmap_allocate(ods_size(datapaths));
+    datapaths->dps_index_map.capacity = ods_size(datapaths);
+
     /* Assign unique sequential indexes to all datapaths.  These are not
      * visible outside of the northd loop, so, unlike the tunnel keys, it
      * doesn't matter if they are different on every iteration. */
-    size_t index = 0;
-
-    datapaths->array = xrealloc(datapaths->array,
-                            ods_size(datapaths) * sizeof *datapaths->array);
-
     struct ovn_datapath *od;
     HMAP_FOR_EACH (od, key_node, &datapaths->datapaths) {
+        size_t index = bitmap_scan(datapaths->dps_index_map.map, 0, 0,
+                                   datapaths->dps_index_map.capacity);
+        bitmap_set1(datapaths->dps_index_map.map, index);
+        datapaths->dps_index_map.n_elems++;
         od->index = index;
-        datapaths->array[index++] = od;
+        vector_push(&datapaths->dps, &od);
         od->datapaths = datapaths;
     }
 }
@@ -3416,7 +3420,8 @@ build_lswitch_lbs_from_lrouter(struct ovn_datapaths 
*lr_datapaths,
     HMAP_FOR_EACH (lb_dps, hmap_node, lb_dps_map) {
         BITMAP_FOR_EACH_1 (index, ods_size(lr_datapaths),
                            lb_dps->nb_lr_map.map) {
-            struct ovn_datapath *od = lr_datapaths->array[index];
+            struct ovn_datapath *od = vector_get(&lr_datapaths->dps, index,
+                                                 struct ovn_datapath *);
             ovn_lb_datapaths_add_ls(lb_dps, vector_len(&od->ls_peers),
                                     vector_get_array(&od->ls_peers),
                                     ods_size(ls_datapaths));
@@ -5019,7 +5024,7 @@ northd_handle_lb_data_changes(struct tracked_lb_data 
*trk_lb_data,
         size_t index;
         BITMAP_FOR_EACH_1 (index, ods_size(ls_datapaths),
                            lb_dps->nb_ls_map.map) {
-            od = ls_datapaths->array[index];
+            od = vector_get(&ls_datapaths->dps, index, struct ovn_datapath *);
 
             /* Add the ls datapath to the northd tracked data. */
             hmapx_add(&nd_changes->ls_with_changed_lbs, od);
@@ -5155,7 +5160,7 @@ northd_handle_lb_data_changes(struct tracked_lb_data 
*trk_lb_data,
         size_t index;
         BITMAP_FOR_EACH_1 (index, ods_size(ls_datapaths),
                            lb_dps->nb_ls_map.map) {
-            od = ls_datapaths->array[index];
+            od = vector_get(&ls_datapaths->dps, index, struct ovn_datapath *);
 
             /* Add the ls datapath to the northd tracked data. */
             hmapx_add(&nd_changes->ls_with_changed_lbs, od);
@@ -8099,7 +8104,8 @@ build_lb_rules(struct lflow_table *lflows, struct 
ovn_lb_datapaths *lb_dps,
                                         ods_size(ls_datapaths));
             BITMAP_FOR_EACH_1 (index, ods_size(ls_datapaths),
                                lb_dps->nb_ls_map.map) {
-                struct ovn_datapath *od = ls_datapaths->array[index];
+                struct ovn_datapath *od = vector_get(&ls_datapaths->dps, index,
+                                                     struct ovn_datapath *);
 
                 meter = copp_meter_get(COPP_REJECT, od->nbs->copp,
                                        meter_groups);
@@ -12104,7 +12110,8 @@ build_gw_lrouter_nat_flows_for_lb(struct 
lrouter_nat_lb_flows_ctx *ctx,
     if (ctx->reject) {
         dp_non_meter = bitmap_clone(dp_bitmap, bitmap_len);
         BITMAP_FOR_EACH_1 (index, bitmap_len, dp_bitmap) {
-            struct ovn_datapath *od = lr_datapaths->array[index];
+            struct ovn_datapath *od = vector_get(&lr_datapaths->dps, index,
+                                                 struct ovn_datapath *);
             const char *meter;
 
             meter = copp_meter_get(COPP_REJECT, od->nbr->copp,
@@ -12241,7 +12248,8 @@ build_lrouter_nat_flows_for_lb(
     bool use_stateless_nat = smap_get_bool(&lb->nlb->options,
                                            "use_stateless_nat", false);
     BITMAP_FOR_EACH_1 (index, bitmap_len, lb_dps->nb_lr_map.map) {
-        struct ovn_datapath *od = lr_datapaths->array[index];
+        struct ovn_datapath *od = vector_get(&lr_datapaths->dps, index,
+                                             struct ovn_datapath *);
         enum lrouter_nat_lb_flow_type type;
 
         const struct lr_stateful_record *lr_stateful_rec =
@@ -12341,7 +12349,8 @@ build_lswitch_flows_for_lb(struct ovn_lb_datapaths 
*lb_dps,
         size_t index;
         BITMAP_FOR_EACH_1 (index, ods_size(ls_datapaths),
                            lb_dps->nb_ls_map.map) {
-            struct ovn_datapath *od = ls_datapaths->array[index];
+            struct ovn_datapath *od = vector_get(&ls_datapaths->dps, index,
+                                                 struct ovn_datapath *);
 
             ovn_lflow_add_with_hint__(lflows, od,
                                       S_SWITCH_IN_PRE_LB, 130, ds_cstr(match),
@@ -12419,7 +12428,8 @@ build_lrouter_allow_vip_traffic_template(struct 
lflow_table *lflows,
 
     size_t index;
     BITMAP_FOR_EACH_1 (index, ods_size(lr_dps), lb_dps->nb_lr_map.map) {
-        struct ovn_datapath *od = lr_dps->array[index];
+        struct ovn_datapath *od = vector_get(&lr_dps->dps, index,
+                                             struct ovn_datapath *);
         /* Do not drop ip traffic with destination the template VIP. */
         ds_clear(&match);
         ds_put_format(&match, "ip%d.dst == %s",
@@ -12466,7 +12476,8 @@ build_lrouter_flows_for_lb(struct ovn_lb_datapaths 
*lb_dps,
 
         BITMAP_FOR_EACH_1 (index, ods_size(lr_datapaths),
                            lb_dps->nb_lr_map.map) {
-            struct ovn_datapath *od = lr_datapaths->array[index];
+            struct ovn_datapath *od = vector_get(&lr_datapaths->dps, index,
+                                                 struct ovn_datapath *);
 
             ovn_lflow_add_with_hint__(lflows, od, S_ROUTER_IN_DNAT,
                                       130, ds_cstr(match), ds_cstr(action),
@@ -12481,7 +12492,8 @@ build_lrouter_flows_for_lb(struct ovn_lb_datapaths 
*lb_dps,
     if (lb->skip_snat) {
         BITMAP_FOR_EACH_1 (index, ods_size(lr_datapaths),
                            lb_dps->nb_lr_map.map) {
-            struct ovn_datapath *od = lr_datapaths->array[index];
+            struct ovn_datapath *od = vector_get(&lr_datapaths->dps, index,
+                                                 struct ovn_datapath *);
 
             ovn_lflow_add(lflows, od, S_ROUTER_OUT_SNAT, 120,
                           "flags.skip_snat_for_lb == 1 && ip", "next;",
@@ -18931,7 +18943,6 @@ static void
 ovn_datapaths_init(struct ovn_datapaths *datapaths)
 {
     hmap_init(&datapaths->datapaths);
-    datapaths->array = NULL;
 }
 
 static void
@@ -18943,8 +18954,8 @@ ovn_datapaths_destroy(struct ovn_datapaths *datapaths)
     }
     hmap_destroy(&datapaths->datapaths);
 
-    free(datapaths->array);
-    datapaths->array = NULL;
+    bitmap_free(datapaths->dps_index_map.map);
+    vector_destroy(&datapaths->dps);
 }
 
 static void
diff --git a/northd/northd.h b/northd/northd.h
index 8f865e8b3..b71b13ca9 100644
--- a/northd/northd.h
+++ b/northd/northd.h
@@ -23,6 +23,7 @@
 #include "northd/en-port-group.h"
 #include "northd/ipam.h"
 #include "openvswitch/hmap.h"
+#include "northd/lb.h"
 #include "simap.h"
 #include "ovs-thread.h"
 #include "en-lr-stateful.h"
@@ -93,7 +94,8 @@ struct ovn_datapaths {
     struct hmap datapaths;
 
     /* The array index of each element in 'datapaths'. */
-    struct ovn_datapath **array;
+    struct dynamic_bitmap dps_index_map;
+    struct vector dps;
 };
 
 static inline size_t
@@ -457,7 +459,7 @@ ovn_datapaths_find_by_index(const struct ovn_datapaths 
*ovn_datapaths,
                             size_t od_index)
 {
     ovs_assert(od_index <= hmap_count(&ovn_datapaths->datapaths));
-    return ovn_datapaths->array[od_index];
+    return vector_get(&ovn_datapaths->dps, od_index, struct ovn_datapath *);
 }
 
 struct ovn_datapath *ovn_datapath_from_sbrec(
-- 
2.50.1

_______________________________________________
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to