[ovs-dev] [PATCH 07/22] ovn-controller: Pass 'chassis_id' explicitly to functions that need it.

Ben Pfaff blp at nicira.com
Sun Jul 19 22:44:53 UTC 2015


I found it otherwise difficult to see what code depended on this.

Signed-off-by: Ben Pfaff <blp at nicira.com>
---
 ovn/controller/binding.c        | 13 +++++++------
 ovn/controller/binding.h        |  5 +++--
 ovn/controller/chassis.c        | 14 +++++++-------
 ovn/controller/chassis.h        |  4 ++--
 ovn/controller/encaps.c         |  7 ++++---
 ovn/controller/encaps.h         |  4 ++--
 ovn/controller/ovn-controller.c | 25 +++++++++++++------------
 ovn/controller/ovn-controller.h |  2 --
 ovn/controller/physical.c       |  4 ++--
 ovn/controller/physical.h       |  1 +
 10 files changed, 41 insertions(+), 38 deletions(-)

diff --git a/ovn/controller/binding.c b/ovn/controller/binding.c
index f3b1e16..2cb0b42 100644
--- a/ovn/controller/binding.c
+++ b/ovn/controller/binding.c
@@ -72,7 +72,8 @@ get_local_iface_ids(const struct ovsrec_bridge *br_int, struct sset *lports)
 }
 
 void
-binding_run(struct controller_ctx *ctx, const struct ovsrec_bridge *br_int)
+binding_run(struct controller_ctx *ctx, const struct ovsrec_bridge *br_int,
+            const char *chassis_id)
 {
     const struct sbrec_chassis *chassis_rec;
     const struct sbrec_binding *binding_rec;
@@ -83,7 +84,7 @@ binding_run(struct controller_ctx *ctx, const struct ovsrec_bridge *br_int)
         return;
     }
 
-    chassis_rec = get_chassis_by_name(ctx->ovnsb_idl, ctx->chassis_id);
+    chassis_rec = get_chassis_by_name(ctx->ovnsb_idl, chassis_id);
     if (!chassis_rec) {
         return;
     }
@@ -95,7 +96,7 @@ binding_run(struct controller_ctx *ctx, const struct ovsrec_bridge *br_int)
 
     ovsdb_idl_txn_add_comment(ctx->ovnsb_idl_txn,
                               "ovn-controller: updating bindings for '%s'",
-                              ctx->chassis_id);
+                              chassis_id);
 
     SBREC_BINDING_FOR_EACH(binding_rec, ctx->ovnsb_idl) {
         if (sset_find_and_delete(&lports, binding_rec->logical_port) ||
@@ -126,21 +127,21 @@ binding_run(struct controller_ctx *ctx, const struct ovsrec_bridge *br_int)
 /* Returns true if the database is all cleaned up, false if more work is
  * required. */
 bool
-binding_cleanup(struct controller_ctx *ctx)
+binding_cleanup(struct controller_ctx *ctx, const char *chassis_id)
 {
     if (!ctx->ovnsb_idl_txn) {
         return false;
     }
 
     const struct sbrec_chassis *chassis_rec
-        = get_chassis_by_name(ctx->ovnsb_idl, ctx->chassis_id);
+        = get_chassis_by_name(ctx->ovnsb_idl, chassis_id);
     if (!chassis_rec) {
         return true;
     }
 
     ovsdb_idl_txn_add_comment(ctx->ovnsb_idl_txn,
                               "ovn-controller: removing all bindings for '%s'",
-                              ctx->chassis_id);
+                              chassis_id);
 
     const struct sbrec_binding *binding_rec;
     bool any_changes = false;
diff --git a/ovn/controller/binding.h b/ovn/controller/binding.h
index dbcc6fb..c60235f 100644
--- a/ovn/controller/binding.h
+++ b/ovn/controller/binding.h
@@ -23,7 +23,8 @@ struct controller_ctx;
 struct ovsrec_bridge;
 
 void binding_init(struct controller_ctx *);
-void binding_run(struct controller_ctx *, const struct ovsrec_bridge *br_int);
-bool binding_cleanup(struct controller_ctx *);
+void binding_run(struct controller_ctx *, const struct ovsrec_bridge *br_int,
+                 const char *chassis_id);
+bool binding_cleanup(struct controller_ctx *, const char *chassis_id);
 
 #endif /* ovn/binding.h */
diff --git a/ovn/controller/chassis.c b/ovn/controller/chassis.c
index 5f1c194..511d5c9 100644
--- a/ovn/controller/chassis.c
+++ b/ovn/controller/chassis.c
@@ -31,7 +31,7 @@ chassis_init(struct controller_ctx *ctx)
 }
 
 void
-chassis_run(struct controller_ctx *ctx)
+chassis_run(struct controller_ctx *ctx, const char *chassis_id)
 {
     if (!ctx->ovnsb_idl_txn) {
         return;
@@ -43,7 +43,7 @@ chassis_run(struct controller_ctx *ctx)
     struct sbrec_encap *encap_rec;
     static bool inited = false;
 
-    chassis_rec = get_chassis_by_name(ctx->ovnsb_idl, ctx->chassis_id);
+    chassis_rec = get_chassis_by_name(ctx->ovnsb_idl, chassis_id);
 
     /* xxx Need to support more than one encap.  Also need to support
      * xxx encap options. */
@@ -82,11 +82,11 @@ chassis_run(struct controller_ctx *ctx)
 
     ovsdb_idl_txn_add_comment(ctx->ovnsb_idl_txn,
                               "ovn-controller: registering chassis '%s'",
-                              ctx->chassis_id);
+                              chassis_id);
 
     if (!chassis_rec) {
         chassis_rec = sbrec_chassis_insert(ctx->ovnsb_idl_txn);
-        sbrec_chassis_set_name(chassis_rec, ctx->chassis_id);
+        sbrec_chassis_set_name(chassis_rec, chassis_id);
     }
 
     encap_rec = sbrec_encap_insert(ctx->ovnsb_idl_txn);
@@ -102,18 +102,18 @@ chassis_run(struct controller_ctx *ctx)
 /* Returns true if the database is all cleaned up, false if more work is
  * required. */
 bool
-chassis_cleanup(struct controller_ctx *ctx)
+chassis_cleanup(struct controller_ctx *ctx, const char *chassis_id)
 {
     /* Delete Chassis row. */
     const struct sbrec_chassis *chassis_rec
-        = get_chassis_by_name(ctx->ovnsb_idl, ctx->chassis_id);
+        = get_chassis_by_name(ctx->ovnsb_idl, chassis_id);
     if (!chassis_rec) {
         return true;
     }
     if (ctx->ovnsb_idl_txn) {
         ovsdb_idl_txn_add_comment(ctx->ovnsb_idl_txn,
                                   "ovn-controller: unregistering chassis '%s'",
-                                  ctx->chassis_id);
+                                  chassis_id);
         sbrec_chassis_delete(chassis_rec);
     }
     return false;
diff --git a/ovn/controller/chassis.h b/ovn/controller/chassis.h
index 18582ec..24648b2 100644
--- a/ovn/controller/chassis.h
+++ b/ovn/controller/chassis.h
@@ -22,7 +22,7 @@ struct controller_ctx;
 struct ovsrec_bridge;
 
 void chassis_init(struct controller_ctx *);
-void chassis_run(struct controller_ctx *);
-bool chassis_cleanup(struct controller_ctx *);
+void chassis_run(struct controller_ctx *, const char *chassis_id);
+bool chassis_cleanup(struct controller_ctx *, const char *chassis_id);
 
 #endif /* ovn/chassis.h */
diff --git a/ovn/controller/encaps.c b/ovn/controller/encaps.c
index 529bf1e..7aa523f 100644
--- a/ovn/controller/encaps.c
+++ b/ovn/controller/encaps.c
@@ -228,7 +228,8 @@ preferred_encap(const struct sbrec_chassis *chassis_rec)
 }
 
 void
-encaps_run(struct controller_ctx *ctx, const struct ovsrec_bridge *br_int)
+encaps_run(struct controller_ctx *ctx, const struct ovsrec_bridge *br_int,
+           const char *chassis_id)
 {
     if (!ctx->ovs_idl_txn) {
         return;
@@ -246,7 +247,7 @@ encaps_run(struct controller_ctx *ctx, const struct ovsrec_bridge *br_int)
     tc.ovs_txn = ctx->ovs_idl_txn;
     ovsdb_idl_txn_add_comment(tc.ovs_txn,
                               "ovn-controller: modifying OVS tunnels '%s'",
-                              ctx->chassis_id);
+                              chassis_id);
 
     /* Collect all port names into tc.port_names.
      *
@@ -270,7 +271,7 @@ encaps_run(struct controller_ctx *ctx, const struct ovsrec_bridge *br_int)
     }
 
     SBREC_CHASSIS_FOR_EACH(chassis_rec, ctx->ovnsb_idl) {
-        if (strcmp(chassis_rec->name, ctx->chassis_id)) {
+        if (strcmp(chassis_rec->name, chassis_id)) {
             /* Create tunnels to the other chassis. */
             const struct sbrec_encap *encap = preferred_encap(chassis_rec);
             if (!encap) {
diff --git a/ovn/controller/encaps.h b/ovn/controller/encaps.h
index 0ec132d..d1b00f2 100644
--- a/ovn/controller/encaps.h
+++ b/ovn/controller/encaps.h
@@ -23,8 +23,8 @@ struct ovsrec_bridge;
 
 void encaps_init(struct controller_ctx *);
 void encaps_run(struct controller_ctx *,
-                 const struct ovsrec_bridge *br_int);
+                const struct ovsrec_bridge *br_int, const char *chassis_id);
 bool encaps_cleanup(struct controller_ctx *,
-                     const struct ovsrec_bridge *br_int);
+                    const struct ovsrec_bridge *br_int);
 
 #endif /* ovn/encaps.h */
diff --git a/ovn/controller/ovn-controller.c b/ovn/controller/ovn-controller.c
index 202486b..5ce44b3 100644
--- a/ovn/controller/ovn-controller.c
+++ b/ovn/controller/ovn-controller.c
@@ -94,7 +94,8 @@ get_bridge(struct controller_ctx *ctx, const char *name)
  * xxx ovn-controller does not support changing any of these mid-run,
  * xxx but that should be addressed later. */
 static void
-get_core_config(struct controller_ctx *ctx, char **br_int_namep)
+get_core_config(struct controller_ctx *ctx, char **br_int_namep,
+                char **chassis_idp)
 {
     while (1) {
         const struct ovsrec_open_vswitch *cfg;
@@ -135,7 +136,7 @@ get_core_config(struct controller_ctx *ctx, char **br_int_namep)
         }
 
         ovnsb_remote = xstrdup(remote);
-        ctx->chassis_id = xstrdup(system_id);
+        *chassis_idp = xstrdup(system_id);
         *br_int_namep = xstrdup(br_int_name);
         return;
 
@@ -222,7 +223,7 @@ int
 main(int argc, char *argv[])
 {
     struct unixctl_server *unixctl;
-    struct controller_ctx ctx = { .chassis_id = NULL };
+    struct controller_ctx ctx = { .ovs_idl = NULL };
     bool exiting;
     int retval;
 
@@ -263,8 +264,8 @@ main(int argc, char *argv[])
 
     get_initial_snapshot(ctx.ovs_idl);
 
-    char *br_int_name;
-    get_core_config(&ctx, &br_int_name);
+    char *br_int_name, *chassis_id;
+    get_core_config(&ctx, &br_int_name, &chassis_id);
 
     ctx.ovnsb_idl = ovsdb_idl_create(ovnsb_remote, &sbrec_idl_class,
                                      true, true);
@@ -288,13 +289,13 @@ main(int argc, char *argv[])
             goto exit;
         }
 
-        chassis_run(&ctx);
-        encaps_run(&ctx, br_int);
-        binding_run(&ctx, br_int);
+        chassis_run(&ctx, chassis_id);
+        encaps_run(&ctx, br_int, chassis_id);
+        binding_run(&ctx, br_int, chassis_id);
 
         struct hmap flow_table = HMAP_INITIALIZER(&flow_table);
         pipeline_run(&ctx, &flow_table);
-        physical_run(&ctx, br_int, &flow_table);
+        physical_run(&ctx, br_int, chassis_id, &flow_table);
         ofctrl_run(br_int, &flow_table);
         hmap_destroy(&flow_table);
 
@@ -329,8 +330,8 @@ main(int argc, char *argv[])
 
         /* Run all of the cleanup functions, even if one of them returns false.
          * We're done if all of them return true. */
-        done = binding_cleanup(&ctx);
-        done = chassis_cleanup(&ctx) && done;
+        done = binding_cleanup(&ctx, chassis_id);
+        done = chassis_cleanup(&ctx, chassis_id) && done;
         done = encaps_cleanup(&ctx, br_int) && done;
         if (done) {
             poll_immediate_wake();
@@ -350,7 +351,7 @@ exit:
     idl_loop_destroy(&ovnsb_idl_loop);
 
     free(br_int_name);
-    free(ctx.chassis_id);
+    free(chassis_id);
     free(ovnsb_remote);
     free(ovs_remote);
 
diff --git a/ovn/controller/ovn-controller.h b/ovn/controller/ovn-controller.h
index 10b96fa..be89b5f 100644
--- a/ovn/controller/ovn-controller.h
+++ b/ovn/controller/ovn-controller.h
@@ -20,8 +20,6 @@
 #include "ovn/lib/ovn-sb-idl.h"
 
 struct controller_ctx {
-    char *chassis_id;               /* ID for this chassis. */
-
     struct ovsdb_idl *ovnsb_idl;
     struct ovsdb_idl_txn *ovnsb_idl_txn;
 
diff --git a/ovn/controller/physical.c b/ovn/controller/physical.c
index febeaaa..5dafdf6 100644
--- a/ovn/controller/physical.c
+++ b/ovn/controller/physical.c
@@ -44,7 +44,7 @@ physical_init(struct controller_ctx *ctx)
 
 void
 physical_run(struct controller_ctx *ctx, const struct ovsrec_bridge *br_int,
-             struct hmap *flow_table)
+             const char *this_chassis_id, struct hmap *flow_table)
 {
     struct simap lport_to_ofport = SIMAP_INITIALIZER(&lport_to_ofport);
     struct simap chassis_to_ofport = SIMAP_INITIALIZER(&chassis_to_ofport);
@@ -56,7 +56,7 @@ physical_run(struct controller_ctx *ctx, const struct ovsrec_bridge *br_int,
 
         const char *chassis_id = smap_get(&port_rec->external_ids,
                                           "ovn-chassis-id");
-        if (chassis_id && !strcmp(chassis_id, ctx->chassis_id)) {
+        if (chassis_id && !strcmp(chassis_id, this_chassis_id)) {
             continue;
         }
 
diff --git a/ovn/controller/physical.h b/ovn/controller/physical.h
index 16d172b..3c86a7f 100644
--- a/ovn/controller/physical.h
+++ b/ovn/controller/physical.h
@@ -30,6 +30,7 @@ struct ovsrec_bridge;
 
 void physical_init(struct controller_ctx *);
 void physical_run(struct controller_ctx *, const struct ovsrec_bridge *br_int,
+                  const char *chassis_id, 
                   struct hmap *flow_table);
 
 #endif /* ovn/physical.h */
-- 
2.1.3




More information about the dev mailing list