This commit changes the type of 'chassis' column in 'Binding' table from string to weak reference of 'Chassis' table entry. This will make accessing the chassis from binding more efficient.
Signed-off-by: Alex Wang <al...@nicira.com> --- ovn/controller/binding.c | 35 ++++++++++++++++++++++++++--------- ovn/controller/physical.c | 2 +- ovn/northd/ovn-northd.c | 4 ++-- ovn/ovn-sb.ovsschema | 5 ++++- ovn/ovn-sb.xml | 3 +-- 5 files changed, 34 insertions(+), 15 deletions(-) diff --git a/ovn/controller/binding.c b/ovn/controller/binding.c index ab6d9f9..b51d6a7 100644 --- a/ovn/controller/binding.c +++ b/ovn/controller/binding.c @@ -74,6 +74,7 @@ get_local_iface_ids(struct controller_ctx *ctx, struct sset *lports) void binding_run(struct controller_ctx *ctx) { + const struct sbrec_chassis *chassis_rec; const struct sbrec_binding *binding_rec; struct ovsdb_idl_txn *txn; struct sset lports, all_lports; @@ -85,6 +86,13 @@ binding_run(struct controller_ctx *ctx) get_local_iface_ids(ctx, &lports); sset_clone(&all_lports, &lports); + SBREC_CHASSIS_FOR_EACH(chassis_rec, ctx->ovnsb_idl) { + if (!strcmp(chassis_rec->name, ctx->chassis_id)) { + break; + } + } + ovs_assert(chassis_rec); + txn = ovsdb_idl_txn_create(ctx->ovnsb_idl); ovsdb_idl_txn_add_comment(txn, "ovn-controller: updating bindings for '%s'", @@ -94,17 +102,18 @@ binding_run(struct controller_ctx *ctx) if (sset_find_and_delete(&lports, binding_rec->logical_port) || (binding_rec->parent_port && binding_rec->parent_port[0] && sset_contains(&all_lports, binding_rec->parent_port))) { - if (!strcmp(binding_rec->chassis, ctx->chassis_id)) { + if (binding_rec->chassis == chassis_rec) { continue; } - if (binding_rec->chassis[0]) { + if (binding_rec->chassis) { VLOG_INFO("Changing chassis for lport %s from %s to %s", - binding_rec->logical_port, binding_rec->chassis, - ctx->chassis_id); + binding_rec->logical_port, + binding_rec->chassis->name, + chassis_rec->name); } - sbrec_binding_set_chassis(binding_rec, ctx->chassis_id); - } else if (!strcmp(binding_rec->chassis, ctx->chassis_id)) { - sbrec_binding_set_chassis(binding_rec, ""); + sbrec_binding_set_chassis(binding_rec, chassis_rec); + } else if (binding_rec->chassis == chassis_rec) { + sbrec_binding_set_chassis(binding_rec, NULL); } } @@ -126,10 +135,18 @@ binding_run(struct controller_ctx *ctx) void binding_destroy(struct controller_ctx *ctx) { + const struct sbrec_chassis *chassis_rec; int retval = TXN_TRY_AGAIN; ovs_assert(ctx->ovnsb_idl); + SBREC_CHASSIS_FOR_EACH(chassis_rec, ctx->ovnsb_idl) { + if (!strcmp(chassis_rec->name, ctx->chassis_id)) { + break; + } + } + ovs_assert(chassis_rec); + while (retval != TXN_SUCCESS && retval != TXN_UNCHANGED) { const struct sbrec_binding *binding_rec; struct ovsdb_idl_txn *txn; @@ -140,8 +157,8 @@ binding_destroy(struct controller_ctx *ctx) ctx->chassis_id); SBREC_BINDING_FOR_EACH(binding_rec, ctx->ovnsb_idl) { - if (!strcmp(binding_rec->chassis, ctx->chassis_id)) { - sbrec_binding_set_chassis(binding_rec, ""); + if (binding_rec->chassis == chassis_rec) { + sbrec_binding_set_chassis(binding_rec, NULL); } } diff --git a/ovn/controller/physical.c b/ovn/controller/physical.c index 0fb43c0..dc2fcee 100644 --- a/ovn/controller/physical.c +++ b/ovn/controller/physical.c @@ -116,7 +116,7 @@ physical_run(struct controller_ctx *ctx) bool local = ofport != 0; if (!local) { ofport = u16_to_ofp(simap_get(&chassis_to_ofport, - binding->chassis)); + binding->chassis->name)); if (!ofport) { continue; } diff --git a/ovn/northd/ovn-northd.c b/ovn/northd/ovn-northd.c index cfad6be..f00e43e 100644 --- a/ovn/northd/ovn-northd.c +++ b/ovn/northd/ovn-northd.c @@ -660,10 +660,10 @@ ovnsb_db_changed(struct northd_context *ctx) continue; } - if (*binding->chassis && (!lport->up || !*lport->up)) { + if (binding->chassis && (!lport->up || !*lport->up)) { bool up = true; nbrec_logical_port_set_up(lport, &up, 1); - } else if (!*binding->chassis && (!lport->up || *lport->up)) { + } else if (!binding->chassis && (!lport->up || *lport->up)) { bool up = false; nbrec_logical_port_set_up(lport, &up, 1); } diff --git a/ovn/ovn-sb.ovsschema b/ovn/ovn-sb.ovsschema index 699bfc5..a688e76 100644 --- a/ovn/ovn-sb.ovsschema +++ b/ovn/ovn-sb.ovsschema @@ -59,7 +59,10 @@ "minInteger": 0, "maxInteger": 4095}, "min": 0, "max": 1}}, - "chassis": {"type": "string"}, + "chassis": {"type": {"key": {"type": "uuid", + "refTable": "Chassis", + "refType": "weak"}, + "min": 0, "max": 1}}, "mac": {"type": {"key": "string", "min": 0, "max": "unlimited"}}}, diff --git a/ovn/ovn-sb.xml b/ovn/ovn-sb.xml index 334d11a..fdf59f0 100644 --- a/ovn/ovn-sb.xml +++ b/ovn/ovn-sb.xml @@ -711,8 +711,7 @@ <column name="chassis"> The physical location of the logical port. To successfully identify a - chassis, this column must match the <ref table="Chassis" column="name"/> - column in some row in the <ref table="Chassis"/> table. This is + chassis, this column must be a <ref table="Chassis"/> record. This is populated by <code>ovn-controller</code>. </column> -- 1.7.9.5 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev