[ovs-dev] [PATCH 11/22] ovn-controller: Honor external-ids:ovn-bridge changing.

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


Until now, if external-ids:ovn-bridge changed, ovn-controller ignored
the change.  With this commit, ovn-controller uses the new bridge.

Signed-off-by: Ben Pfaff <blp at nicira.com>
---
 ovn/controller/ovn-controller.c | 81 +++++++++++++++++------------------------
 1 file changed, 33 insertions(+), 48 deletions(-)

diff --git a/ovn/controller/ovn-controller.c b/ovn/controller/ovn-controller.c
index d67f3c2..cf21a51 100644
--- a/ovn/controller/ovn-controller.c
+++ b/ovn/controller/ovn-controller.c
@@ -56,8 +56,6 @@ static void parse_options(int argc, char *argv[]);
 OVS_NO_RETURN static void usage(void);
 
 static char *ovs_remote;
-static char *ovnsb_remote;
-
 
 static void
 get_initial_snapshot(struct ovsdb_idl *idl)
@@ -73,12 +71,21 @@ get_initial_snapshot(struct ovsdb_idl *idl)
 }
 
 static const struct ovsrec_bridge *
-get_bridge(struct controller_ctx *ctx, const char *name)
+get_br_int(struct ovsdb_idl *ovs_idl)
 {
-    const struct ovsrec_bridge *br;
+    const struct ovsrec_open_vswitch *cfg = ovsrec_open_vswitch_first(ovs_idl);
+    if (!cfg) {
+        return NULL;
+    }
+
+    const char *br_int_name = smap_get(&cfg->external_ids, "ovn-bridge");
+    if (!br_int_name) {
+        br_int_name = DEFAULT_BRIDGE_NAME;
+    }
 
-    OVSREC_BRIDGE_FOR_EACH(br, ctx->ovs_idl) {
-        if (!strcmp(br->name, name)) {
+    const struct ovsrec_bridge *br;
+    OVSREC_BRIDGE_FOR_EACH (br, ovs_idl) {
+        if (!strcmp(br->name, br_int_name)) {
             return br;
         }
     }
@@ -93,49 +100,30 @@ get_chassis_id(const struct ovsdb_idl *ovs_idl)
     return cfg ? smap_get(&cfg->external_ids, "system-id") : NULL;
 }
 
-/* Retrieve the OVN integration bridge from the "external-ids:ovn-bridge"
- * key, the remote location from the "external-ids:ovn-remote" key, and
- * the chassis name from the "external-ids:system-id" key in the
- * Open_vSwitch table of the OVS database instance.
+/* Retrieves the OVN Southbound remote location from the
+ * "external-ids:ovn-remote" key in 'ovs_idl' and returns a copy of it.
  *
- * 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)
+ * XXX ovn-controller does not support this changing mid-run, but that should
+ * be addressed later. */
+static char *
+get_ovnsb_remote(struct ovsdb_idl *ovs_idl)
 {
     while (1) {
-        const struct ovsrec_open_vswitch *cfg;
-        cfg = ovsrec_open_vswitch_first(ctx->ovs_idl);
-        if (!cfg) {
-            VLOG_ERR("No Open_vSwitch row defined.");
-            ovsdb_idl_destroy(ctx->ovs_idl);
-            exit(EXIT_FAILURE);
-        }
-
-        const char *remote, *br_int_name;
-
-        ovsdb_idl_run(ctx->ovs_idl);
-
-        br_int_name = smap_get(&cfg->external_ids, "ovn-bridge");
-        if (!br_int_name) {
-            br_int_name = DEFAULT_BRIDGE_NAME;
-        }
-
-        remote = smap_get(&cfg->external_ids, "ovn-remote");
-        if (!remote) {
-            VLOG_INFO("OVN OVSDB remote not specified.  Waiting...");
-            goto try_again;
+        ovsdb_idl_run(ovs_idl);
+
+        const struct ovsrec_open_vswitch *cfg
+            = ovsrec_open_vswitch_first(ovs_idl);
+        if (cfg) {
+            const char *remote = smap_get(&cfg->external_ids, "ovn-remote");
+            if (remote) {
+                return xstrdup(remote);
+            }
         }
 
-        ovnsb_remote = xstrdup(remote);
-        *br_int_namep = xstrdup(br_int_name);
-        return;
-
-try_again:
-        ovsdb_idl_wait(ctx->ovs_idl);
+        VLOG_INFO("OVN OVSDB remote not specified.  Waiting...");
+        ovsdb_idl_wait(ovs_idl);
         poll_block();
     }
-
 }
 
 struct idl_loop {
@@ -252,9 +240,7 @@ main(int argc, char *argv[])
 
     get_initial_snapshot(ctx.ovs_idl);
 
-    char *br_int_name;
-    get_core_config(&ctx, &br_int_name);
-
+    char *ovnsb_remote = get_ovnsb_remote(ctx.ovs_idl);
     ctx.ovnsb_idl = ovsdb_idl_create(ovnsb_remote, &sbrec_idl_class,
                                      true, true);
     get_initial_snapshot(ctx.ovnsb_idl);
@@ -268,7 +254,7 @@ main(int argc, char *argv[])
         ctx.ovnsb_idl_txn = idl_loop_run(&ovnsb_idl_loop);
         ctx.ovs_idl_txn = idl_loop_run(&ovs_idl_loop);
 
-        const struct ovsrec_bridge *br_int = get_bridge(&ctx, br_int_name);
+        const struct ovsrec_bridge *br_int = get_br_int(ctx.ovs_idl);
         const char *chassis_id = get_chassis_id(ctx.ovs_idl);
 
         if (chassis_id) {
@@ -309,7 +295,7 @@ main(int argc, char *argv[])
         ctx.ovnsb_idl_txn = idl_loop_run(&ovnsb_idl_loop);
         ctx.ovs_idl_txn = idl_loop_run(&ovs_idl_loop);
 
-        const struct ovsrec_bridge *br_int = get_bridge(&ctx, br_int_name);
+        const struct ovsrec_bridge *br_int = get_br_int(ctx.ovs_idl);
         const char *chassis_id = get_chassis_id(ctx.ovs_idl);
 
         /* Run all of the cleanup functions, even if one of them returns false.
@@ -333,7 +319,6 @@ main(int argc, char *argv[])
     idl_loop_destroy(&ovs_idl_loop);
     idl_loop_destroy(&ovnsb_idl_loop);
 
-    free(br_int_name);
     free(ovnsb_remote);
     free(ovs_remote);
 
-- 
2.1.3




More information about the dev mailing list