From: Ben Pfaff Date: Wed, 29 Jul 2015 15:48:26 +0000 (-0700) Subject: ovn-controller: Pass 'chassis_id' explicitly to functions that need it. X-Git-Tag: v2.5.0~841 X-Git-Url: http://git.cascardo.eti.br/?a=commitdiff_plain;h=4acc496ecd359088cdf1ce4d549c65828f928e72;p=cascardo%2Fovs.git ovn-controller: Pass 'chassis_id' explicitly to functions that need it. I found it otherwise difficult to see what code depended on this. When later commits make it possible for ovn-controller to handle changes in chassis ID, this will become important (the code should determine the current chassis ID before trying to use it). Signed-off-by: Ben Pfaff Acked-by: Justin Pettit --- diff --git a/ovn/controller/binding.c b/ovn/controller/binding.c index f3b1e1627..2cb0b42d2 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 dbcc6fbb5..c60235f15 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 5f1c19472..511d5c90f 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 18582ecbc..24648b2a4 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 529bf1ef7..7aa523f8a 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 0ec132db7..d1b00f290 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 15c4a3dc6..b7b1599d7 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) { ovsdb_idl_run(ctx->ovs_idl); @@ -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; @@ -234,7 +235,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; @@ -275,8 +276,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); @@ -300,13 +301,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); @@ -341,8 +342,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(); @@ -362,7 +363,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 10b96fadd..be89b5fb8 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 3a1d44794..010883ae9 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 16d172bbb..099659d0f 100644 --- a/ovn/controller/physical.h +++ b/ovn/controller/physical.h @@ -30,6 +30,6 @@ struct ovsrec_bridge; void physical_init(struct controller_ctx *); void physical_run(struct controller_ctx *, const struct ovsrec_bridge *br_int, - struct hmap *flow_table); + const char *chassis_id, struct hmap *flow_table); #endif /* ovn/physical.h */