From: Alex Wang Date: Tue, 19 May 2015 21:22:16 +0000 (-0700) Subject: ovn: Change type of 'chassis' column in 'Binding' table. X-Git-Tag: v2.5.0~1068 X-Git-Url: http://git.cascardo.eti.br/?a=commitdiff_plain;h=713322317cf123eaab403c3c39b0faaef1968ceb;p=cascardo%2Fovs.git ovn: Change type of 'chassis' column in 'Binding' table. 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 Acked-by: Ben Pfaff --- diff --git a/ovn/controller/binding.c b/ovn/controller/binding.c index ab6d9f901..0a4a39ef9 100644 --- a/ovn/controller/binding.c +++ b/ovn/controller/binding.c @@ -74,12 +74,18 @@ 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; const char *name; int retval; + chassis_rec = get_chassis_by_name(ctx->ovnsb_idl, ctx->chassis_id); + if (!chassis_rec) { + return; + } + sset_init(&lports); sset_init(&all_lports); get_local_iface_ids(ctx, &lports); @@ -94,17 +100,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 +133,16 @@ 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); + chassis_rec = get_chassis_by_name(ctx->ovnsb_idl, ctx->chassis_id); + if (!chassis_rec) { + return; + } + while (retval != TXN_SUCCESS && retval != TXN_UNCHANGED) { const struct sbrec_binding *binding_rec; struct ovsdb_idl_txn *txn; @@ -140,8 +153,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/chassis.c b/ovn/controller/chassis.c index 1a2bb32ef..63e1160df 100644 --- a/ovn/controller/chassis.c +++ b/ovn/controller/chassis.c @@ -55,11 +55,7 @@ register_chassis(struct controller_ctx *ctx) int retval = TXN_TRY_AGAIN; struct ovsdb_idl_txn *txn; - SBREC_CHASSIS_FOR_EACH(chassis_rec, ctx->ovnsb_idl) { - if (!strcmp(chassis_rec->name, ctx->chassis_id)) { - break; - } - } + chassis_rec = get_chassis_by_name(ctx->ovnsb_idl, ctx->chassis_id); /* xxx Need to support more than one encap. Also need to support * xxx encap options. */ @@ -396,12 +392,7 @@ chassis_destroy(struct controller_ctx *ctx) const struct sbrec_chassis *chassis_rec; struct ovsdb_idl_txn *txn; - SBREC_CHASSIS_FOR_EACH(chassis_rec, ctx->ovnsb_idl) { - if (!strcmp(chassis_rec->name, ctx->chassis_id)) { - break; - } - } - + chassis_rec = get_chassis_by_name(ctx->ovnsb_idl, ctx->chassis_id); if (!chassis_rec) { break; } diff --git a/ovn/controller/ovn-controller.h b/ovn/controller/ovn-controller.h index a1630f768..6f9865833 100644 --- a/ovn/controller/ovn-controller.h +++ b/ovn/controller/ovn-controller.h @@ -17,6 +17,8 @@ #ifndef OVN_CONTROLLER_H #define OVN_CONTROLLER_H 1 +#include "ovn/lib/ovn-sb-idl.h" + struct controller_ctx { char *chassis_id; /* ID for this chassis. */ char *br_int_name; /* Name of local integration bridge. */ @@ -26,4 +28,18 @@ struct controller_ctx { const struct ovsrec_bridge *br_int; }; +static inline const struct sbrec_chassis * +get_chassis_by_name(struct ovsdb_idl *ovnsb_idl, char *chassis_id) +{ + const struct sbrec_chassis *chassis_rec; + + SBREC_CHASSIS_FOR_EACH(chassis_rec, ovnsb_idl) { + if (!strcmp(chassis_rec->name, chassis_id)) { + break; + } + } + + return chassis_rec; +} + #endif /* ovn/ovn-controller.h */ diff --git a/ovn/controller/physical.c b/ovn/controller/physical.c index 0fb43c091..dc2fcee5b 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 2676b0dfc..39df3b5db 100644 --- a/ovn/northd/ovn-northd.c +++ b/ovn/northd/ovn-northd.c @@ -663,10 +663,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 699bfc535..a688e7675 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 334d11a0c..fdf59f05d 100644 --- a/ovn/ovn-sb.xml +++ b/ovn/ovn-sb.xml @@ -711,8 +711,7 @@ The physical location of the logical port. To successfully identify a - chassis, this column must match the - column in some row in the table. This is + chassis, this column must be a record. This is populated by ovn-controller.