2
0
mirror of https://github.com/openvswitch/ovs synced 2025-09-01 14:55:18 +00:00

ovn: Make column comparisons more generic.

The logic in ovn-northd's parents_equal() and tags_equal() is useful
for other columns, so convert them into more generic functions that
can be reused.

Signed-off-by: Russell Bryant <rbryant@redhat.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
This commit is contained in:
Russell Bryant
2015-07-21 12:59:13 -04:00
committed by Ben Pfaff
parent 422a9f73d3
commit 34f3e8406b

View File

@@ -405,33 +405,41 @@ build_pipeline(struct northd_context *ctx)
hmap_destroy(&pc.pipeline_hmap); hmap_destroy(&pc.pipeline_hmap);
} }
/*
* Take two string columns and return true if:
* - neither are set
* - both are set and the strings are equal
*/
static bool static bool
parents_equal(const struct sbrec_binding *binding, strings_equal(const char *s1, const char *s2)
const struct nbrec_logical_port *lport)
{ {
if (!!binding->parent_port != !!lport->parent_name) { if (!!s1 != !!s2) {
/* One is set and the other is not. */ /* One is set and the other is not. */
return false; return false;
} }
if (binding->parent_port) { if (s1) {
/* Both are set. */ /* Both are set. */
return strcmp(binding->parent_port, lport->parent_name) ? false : true; return strcmp(s1, s2) ? false : true;
} }
/* Both are NULL. */ /* Both are NULL. */
return true; return true;
} }
/*
* Take two int64_t columns and return true if either:
* - neither are set
* - both are set and the first integers in each are equal
*/
static bool static bool
tags_equal(const struct sbrec_binding *binding, int64_first_equal(int64_t *i1, size_t n_i1, int64_t *i2, size_t n_i2)
const struct nbrec_logical_port *lport)
{ {
if (binding->n_tag != lport->n_tag) { if (n_i1 != n_i2) {
return false; return false;
} }
return binding->n_tag ? (binding->tag[0] == lport->tag[0]) : true; return i1 ? (i1[0] == i2[0]) : true;
} }
struct binding_hash_node { struct binding_hash_node {
@@ -538,10 +546,11 @@ set_bindings(struct northd_context *ctx)
sbrec_binding_set_mac(binding, (const char **) lport->macs, sbrec_binding_set_mac(binding, (const char **) lport->macs,
lport->n_macs); lport->n_macs);
} }
if (!parents_equal(binding, lport)) { if (!strings_equal(binding->parent_port, lport->parent_name)) {
sbrec_binding_set_parent_port(binding, lport->parent_name); sbrec_binding_set_parent_port(binding, lport->parent_name);
} }
if (!tags_equal(binding, lport)) { if (!int64_first_equal(binding->tag, binding->n_tag,
lport->tag, lport->n_tag)) {
sbrec_binding_set_tag(binding, lport->tag, lport->n_tag); sbrec_binding_set_tag(binding, lport->tag, lport->n_tag);
} }
if (!uuid_equals(&binding->logical_datapath, if (!uuid_equals(&binding->logical_datapath,