[ovs-dev] [PATCH ovn v4 7/7] northd: Add functionality to runtime node

Mark Gray mark.d.gray at redhat.com
Fri Sep 3 12:21:48 UTC 2021


Update the runtime node to initialize and destroy some common data
used by multiple functions in northd.

Signed-off-by: Mark Gray <mark.d.gray at redhat.com>
---
 northd/en-northd.c  |  9 ++++++++-
 northd/en-runtime.c | 30 ++++++++++++++++++++++++++++--
 northd/en-runtime.h |  8 ++++++++
 northd/northd.c     | 15 +++++----------
 northd/northd.h     |  5 ++++-
 5 files changed, 53 insertions(+), 14 deletions(-)

diff --git a/northd/en-northd.c b/northd/en-northd.c
index d310fa4dd31f..2a3250f3d57a 100644
--- a/northd/en-northd.c
+++ b/northd/en-northd.c
@@ -19,6 +19,7 @@
 #include <stdio.h>
 
 #include "en-northd.h"
+#include "en-runtime.h"
 #include "lib/inc-proc-eng.h"
 #include "northd.h"
 #include "openvswitch/vlog.h"
@@ -29,7 +30,13 @@ void en_northd_run(struct engine_node *node, void *data OVS_UNUSED)
 {
     const struct engine_context *eng_ctx = engine_get_context();
     struct northd_context *ctx = eng_ctx->client_ctx;
-    ovn_db_run(ctx);
+
+    struct ed_type_runtime *runtime_data =
+                         engine_get_input_data("runtime", node);
+
+    ovn_db_run(ctx, &runtime_data->lr_list,
+                    &runtime_data->datapaths,
+                    &runtime_data->ports);
 
     engine_set_node_state(node, EN_UPDATED);
 
diff --git a/northd/en-runtime.c b/northd/en-runtime.c
index aac01cd0351f..b8e5766823bf 100644
--- a/northd/en-runtime.c
+++ b/northd/en-runtime.c
@@ -19,7 +19,9 @@
 #include <stdio.h>
 
 #include "en-runtime.h"
+#include "openvswitch/hmap.h"
 #include "lib/inc-proc-eng.h"
+#include "openvswitch/list.h"
 #include "northd.h"
 #include "openvswitch/vlog.h"
 
@@ -27,14 +29,38 @@ VLOG_DEFINE_THIS_MODULE(en_runtime);
 
 void en_runtime_run(struct engine_node *node, void *data OVS_UNUSED)
 {
+    struct ed_type_runtime *runtime_data = data;
+
+    struct ovs_list *lr_list = &runtime_data->lr_list;
+    struct hmap *datapaths = &runtime_data->datapaths;
+    struct hmap *ports = &runtime_data->ports;
+
+    destroy_datapaths_and_ports(datapaths, ports, lr_list);
+
+    ovs_list_init(lr_list);
+    hmap_init(datapaths);
+    hmap_init(ports);
+
     engine_set_node_state(node, EN_UPDATED);
 }
 void *en_runtime_init(struct engine_node *node OVS_UNUSED,
                      struct engine_arg *arg OVS_UNUSED)
 {
-    return NULL;
+    struct ed_type_runtime *data = xzalloc(sizeof *data);
+    ovs_list_init(&data->lr_list);
+    hmap_init(&data->datapaths);
+    hmap_init(&data->ports);
+
+    return data;
 }
 
-void en_runtime_cleanup(void *data OVS_UNUSED)
+void en_runtime_cleanup(void *data)
 {
+    struct ed_type_runtime *runtime_data = data;
+
+    struct ovs_list *lr_list = &runtime_data->lr_list;
+    struct hmap *datapaths = &runtime_data->datapaths;
+    struct hmap *ports = &runtime_data->ports;
+
+    destroy_datapaths_and_ports(datapaths, ports, lr_list);
 }
diff --git a/northd/en-runtime.h b/northd/en-runtime.h
index 2547c9ec470a..7a1b2f6873e5 100644
--- a/northd/en-runtime.h
+++ b/northd/en-runtime.h
@@ -7,7 +7,15 @@
 #include <stdlib.h>
 #include <stdio.h>
 
+#include "openvswitch/hmap.h"
 #include "lib/inc-proc-eng.h"
+#include "openvswitch/list.h"
+
+struct ed_type_runtime {
+    struct ovs_list lr_list;
+    struct hmap datapaths;
+    struct hmap ports;
+};
 
 void en_runtime_run(struct engine_node *node, void *data);
 void *en_runtime_init(struct engine_node *node,
diff --git a/northd/northd.c b/northd/northd.c
index 829c4479f14b..43792f0d7ff7 100644
--- a/northd/northd.c
+++ b/northd/northd.c
@@ -13838,7 +13838,7 @@ sync_dns_entries(struct northd_context *ctx, struct hmap *datapaths)
     hmap_destroy(&dns_map);
 }
 
-static void
+void
 destroy_datapaths_and_ports(struct hmap *datapaths, struct hmap *ports,
                             struct ovs_list *lr_list)
 {
@@ -14548,13 +14548,9 @@ ovnsb_db_run(struct northd_context *ctx,
 }
 
 void
-ovn_db_run(struct northd_context *ctx)
+ovn_db_run(struct northd_context *ctx, struct ovs_list *lr_list,
+           struct hmap *datapaths, struct hmap *ports)
 {
-    struct hmap datapaths, ports;
-    struct ovs_list lr_list;
-    ovs_list_init(&lr_list);
-    hmap_init(&datapaths);
-    hmap_init(&ports);
     use_parallel_build = ctx->use_parallel_build;
     lflow_locks = ctx->lflow_locks;
 
@@ -14562,12 +14558,11 @@ ovn_db_run(struct northd_context *ctx)
 
     stopwatch_start(OVNNB_DB_RUN_STOPWATCH_NAME, time_msec());
     ovnnb_db_run(ctx, ctx->sbrec_chassis_by_name, ctx->ovnsb_idl_loop,
-                 &datapaths, &ports, &lr_list, start_time,
+                 datapaths, ports, lr_list, start_time,
                  ctx->ovn_internal_version);
     stopwatch_stop(OVNNB_DB_RUN_STOPWATCH_NAME, time_msec());
     stopwatch_start(OVNSB_DB_RUN_STOPWATCH_NAME, time_msec());
-    ovnsb_db_run(ctx, ctx->ovnsb_idl_loop, &ports, start_time);
+    ovnsb_db_run(ctx, ctx->ovnsb_idl_loop, ports, start_time);
     stopwatch_stop(OVNSB_DB_RUN_STOPWATCH_NAME, time_msec());
-    destroy_datapaths_and_ports(&datapaths, &ports, &lr_list);
 }
 
diff --git a/northd/northd.h b/northd/northd.h
index fa941d8ec83b..45a153ba2aa4 100644
--- a/northd/northd.h
+++ b/northd/northd.h
@@ -37,6 +37,9 @@ struct northd_context {
     const char *ovn_internal_version;
 };
 
-void ovn_db_run(struct northd_context *ctx);
+void ovn_db_run(struct northd_context *ctx, struct ovs_list *,
+                struct hmap *, struct hmap *);
+void destroy_datapaths_and_ports(struct hmap *datapaths, struct hmap *ports,
+                                 struct ovs_list *lr_list);
 
 #endif /* NORTHD_H */
-- 
2.27.0



More information about the dev mailing list