From e9011ac83235d37c8c05efee1a200f0879080187 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Thu, 3 Dec 2009 10:35:45 -0800 Subject: [PATCH] ovsdb-idl: Fix resolution of references from one table to another. Our tests only checked references from a table to itself, so of course there were bugs in references from one table to another. This fixes the obvious one and adds a test. --- lib/ovsdb-idl.c | 7 +-- tests/idltest.ovsidl | 15 ++++-- tests/ovsdb-idl.at | 110 +++++++++++++++++++++++++------------------ tests/test-ovsdb.c | 44 ++++++++++------- 4 files changed, 106 insertions(+), 70 deletions(-) diff --git a/lib/ovsdb-idl.c b/lib/ovsdb-idl.c index 26b5942d..691f8a1c 100644 --- a/lib/ovsdb-idl.c +++ b/lib/ovsdb-idl.c @@ -634,13 +634,14 @@ ovsdb_idl_get_row_arc(struct ovsdb_idl_row *src, const struct uuid *dst_uuid) { struct ovsdb_idl *idl = src->table->idl; + struct ovsdb_idl_table *dst_table; struct ovsdb_idl_arc *arc; struct ovsdb_idl_row *dst; - dst = ovsdb_idl_get_row(src->table, dst_uuid); + /* XXX it's slow to have to look up dst_table this way every time */ + dst_table = shash_find_data(&idl->tables, dst_table_class->name); + dst = ovsdb_idl_get_row(dst_table, dst_uuid); if (!dst) { - struct ovsdb_idl_table *dst_table; - dst_table = shash_find_data(&idl->tables, dst_table_class->name); dst = ovsdb_idl_row_create(dst_table, dst_uuid); } diff --git a/tests/idltest.ovsidl b/tests/idltest.ovsidl index ec5cec3e..75d50ef2 100644 --- a/tests/idltest.ovsidl +++ b/tests/idltest.ovsidl @@ -21,9 +21,16 @@ "ba": {"type": {"key": "boolean", "min": 0, "max": "unlimited"}}, "sa": {"type": {"key": "string", "min": 0, "max": "unlimited"}}, "ua": {"type": {"key": "uuid", "min": 0, "max": "unlimited"}}}}, - "selfLink": { + "link1": { "columns": { "i": {"type": "integer"}, - "k": {"type": {"key": "uuid", "keyRefTable": "selfLink"}}, - "ka": {"type": {"key": "uuid", "keyRefTable": "selfLink", - "min": 0, "max": "unlimited"}}}}}} + "k": {"type": {"key": "uuid", "keyRefTable": "link1"}}, + "ka": {"type": {"key": "uuid", "keyRefTable": "link1", + "min": 0, "max": "unlimited"}}, + "l2": {"type": {"key": "uuid", "keyRefTable": "link2", + "min": 0, "max": 1}}}}, + "link2": { + "columns": { + "i": {"type": "integer"}, + "l1": {"type": {"key": "uuid", "keyRefTable": "link1", + "min": 0, "max": 1}}}}}} diff --git a/tests/ovsdb-idl.at b/tests/ovsdb-idl.at index f0e6ff8a..cf931039 100644 --- a/tests/ovsdb-idl.at +++ b/tests/ovsdb-idl.at @@ -140,127 +140,143 @@ OVSDB_CHECK_IDL([simple idl, initially populated], OVSDB_CHECK_IDL([self-linking idl, consistent ops], [], [['[{"op": "insert", - "table": "selfLink", + "table": "link1", "row": {"i": 0, "k": ["named-uuid", "self"]}, "uuid-name": "self"}]' \ '[{"op": "insert", - "table": "selfLink", + "table": "link1", "row": {"i": 1}, "uuid-name": "row1"}, {"op": "insert", - "table": "selfLink", + "table": "link1", "row": {"i": 2, "k": ["named-uuid", "row1"]}, "uuid-name": "row2"}, {"op": "update", - "table": "selfLink", + "table": "link1", "where": [["i", "==", 1]], "row": {"k": ["named-uuid", "row2"]}}]' \ '[{"op": "update", - "table": "selfLink", + "table": "link1", "where": [["i", "==", 1]], "row": {"k": ["uuid", "#1#"]}}]' \ '[{"op": "update", - "table": "selfLink", + "table": "link1", "where": [], "row": {"k": ["uuid", "#0#"]}}]']], [[000: empty 001: {"error":null,"result":[{"uuid":["uuid","<0>"]}]} -002: i=0 k=0 ka=[] uuid=<0> +002: i=0 k=0 ka=[] l2= uuid=<0> 003: {"error":null,"result":[{"uuid":["uuid","<1>"]},{"uuid":["uuid","<2>"]},{"count":1}]} -004: i=0 k=0 ka=[] uuid=<0> -004: i=1 k=2 ka=[] uuid=<1> -004: i=2 k=1 ka=[] uuid=<2> +004: i=0 k=0 ka=[] l2= uuid=<0> +004: i=1 k=2 ka=[] l2= uuid=<1> +004: i=2 k=1 ka=[] l2= uuid=<2> 005: {"error":null,"result":[{"count":1}]} -006: i=0 k=0 ka=[] uuid=<0> -006: i=1 k=1 ka=[] uuid=<1> -006: i=2 k=1 ka=[] uuid=<2> +006: i=0 k=0 ka=[] l2= uuid=<0> +006: i=1 k=1 ka=[] l2= uuid=<1> +006: i=2 k=1 ka=[] l2= uuid=<2> 007: {"error":null,"result":[{"count":3}]} -008: i=0 k=0 ka=[] uuid=<0> -008: i=1 k=0 ka=[] uuid=<1> -008: i=2 k=0 ka=[] uuid=<2> +008: i=0 k=0 ka=[] l2= uuid=<0> +008: i=1 k=0 ka=[] l2= uuid=<1> +008: i=2 k=0 ka=[] l2= uuid=<2> 009: done ]]) OVSDB_CHECK_IDL([self-linking idl, inconsistent ops], [], [['[{"op": "insert", - "table": "selfLink", + "table": "link1", "row": {"i": 0, "k": ["uuid", "cf197cc5-c8c9-42f5-82d5-c71a9f2cb96b"]}}]' \ '[{"op": "update", - "table": "selfLink", + "table": "link1", "where": [], "row": {"k": ["uuid", "#0#"]}}]' \ '[{"op": "update", - "table": "selfLink", + "table": "link1", "where": [], "row": {"k": ["uuid", "c2fca39a-e69a-42a4-9c56-5eca85839ce9"]}}]' \ '[{"op": "insert", - "table": "selfLink", + "table": "link1", "row": {"i": 1, "k": ["uuid", "52d752a3-b062-4668-9446-d2e0d4a14703"]}}]' \ '[{"op": "update", - "table": "selfLink", + "table": "link1", "where": [], "row": {"k": ["uuid", "#1#"]}}]' \ ]], [[000: empty 001: {"error":null,"result":[{"uuid":["uuid","<0>"]}]} -002: i=0 k= ka=[] uuid=<0> +002: i=0 k= ka=[] l2= uuid=<0> 003: {"error":null,"result":[{"count":1}]} -004: i=0 k=0 ka=[] uuid=<0> +004: i=0 k=0 ka=[] l2= uuid=<0> 005: {"error":null,"result":[{"count":1}]} -006: i=0 k= ka=[] uuid=<0> +006: i=0 k= ka=[] l2= uuid=<0> 007: {"error":null,"result":[{"uuid":["uuid","<1>"]}]} -008: i=0 k= ka=[] uuid=<0> -008: i=1 k= ka=[] uuid=<1> +008: i=0 k= ka=[] l2= uuid=<0> +008: i=1 k= ka=[] l2= uuid=<1> 009: {"error":null,"result":[{"count":2}]} -010: i=0 k=1 ka=[] uuid=<0> -010: i=1 k=1 ka=[] uuid=<1> +010: i=0 k=1 ka=[] l2= uuid=<0> +010: i=1 k=1 ka=[] l2= uuid=<1> 011: done ]]) OVSDB_CHECK_IDL([self-linking idl, sets], [], [['[{"op": "insert", - "table": "selfLink", + "table": "link1", "row": {"i": 0, "ka": ["set", [["named-uuid", "i0"]]]}, "uuid-name": "i0"}, {"op": "insert", - "table": "selfLink", + "table": "link1", "row": {"i": 1, "ka": ["set", [["named-uuid", "i1"]]]}, "uuid-name": "i1"}, {"op": "insert", - "table": "selfLink", + "table": "link1", "row": {"i": 2, "ka": ["set", [["named-uuid", "i2"]]]}, "uuid-name": "i2"}, {"op": "insert", - "table": "selfLink", + "table": "link1", "row": {"i": 3, "ka": ["set", [["named-uuid", "i3"]]]}, "uuid-name": "i3"}]' \ '[{"op": "update", - "table": "selfLink", + "table": "link1", "where": [], "row": {"ka": ["set", [["uuid", "#0#"], ["uuid", "#1#"], ["uuid", "#2#"], ["uuid", "#3#"]]]}}]' \ '[{"op": "update", - "table": "selfLink", + "table": "link1", "where": [], "row": {"ka": ["set", [["uuid", "#0#"], ["uuid", "88702e78-845b-4a6e-ad08-cf68922ae84a"], ["uuid", "#2#"], ["uuid", "1ac2b12e-b767-4805-a55d-43976e40c465"]]]}}]']], [[000: empty 001: {"error":null,"result":[{"uuid":["uuid","<0>"]},{"uuid":["uuid","<1>"]},{"uuid":["uuid","<2>"]},{"uuid":["uuid","<3>"]}]} -002: i=0 k= ka=[0] uuid=<0> -002: i=1 k= ka=[1] uuid=<1> -002: i=2 k= ka=[2] uuid=<2> -002: i=3 k= ka=[3] uuid=<3> +002: i=0 k= ka=[0] l2= uuid=<0> +002: i=1 k= ka=[1] l2= uuid=<1> +002: i=2 k= ka=[2] l2= uuid=<2> +002: i=3 k= ka=[3] l2= uuid=<3> 003: {"error":null,"result":[{"count":4}]} -004: i=0 k= ka=[0 1 2 3] uuid=<0> -004: i=1 k= ka=[0 1 2 3] uuid=<1> -004: i=2 k= ka=[0 1 2 3] uuid=<2> -004: i=3 k= ka=[0 1 2 3] uuid=<3> +004: i=0 k= ka=[0 1 2 3] l2= uuid=<0> +004: i=1 k= ka=[0 1 2 3] l2= uuid=<1> +004: i=2 k= ka=[0 1 2 3] l2= uuid=<2> +004: i=3 k= ka=[0 1 2 3] l2= uuid=<3> 005: {"error":null,"result":[{"count":4}]} -006: i=0 k= ka=[0 2] uuid=<0> -006: i=1 k= ka=[0 2] uuid=<1> -006: i=2 k= ka=[0 2] uuid=<2> -006: i=3 k= ka=[0 2] uuid=<3> +006: i=0 k= ka=[0 2] l2= uuid=<0> +006: i=1 k= ka=[0 2] l2= uuid=<1> +006: i=2 k= ka=[0 2] l2= uuid=<2> +006: i=3 k= ka=[0 2] l2= uuid=<3> 007: done ]]) -# XXX self-linking idl, maps + +OVSDB_CHECK_IDL([external-linking idl, consistent ops], + [], + [['[{"op": "insert", + "table": "link2", + "row": {"i": 0}, + "uuid-name": "row0"}, + {"op": "insert", + "table": "link1", + "row": {"i": 1, "l2": ["set", [["named-uuid", "row0"]]]}, + "uuid-name": "row1"}]']], + [[000: empty +001: {"error":null,"result":[{"uuid":["uuid","<0>"]},{"uuid":["uuid","<1>"]}]} +002: i=0 l1= uuid=<0> +002: i=1 k= ka=[] l2=0 uuid=<1> +003: done +]]) diff --git a/tests/test-ovsdb.c b/tests/test-ovsdb.c index f3305edd..fb13df9c 100644 --- a/tests/test-ovsdb.c +++ b/tests/test-ovsdb.c @@ -1232,13 +1232,12 @@ do_transact(int argc, char *argv[]) } static int -compare_selflink(const void *a_, const void *b_) +compare_link1(const void *a_, const void *b_) { - const struct idltest_selflink *const *ap = a_; - const struct idltest_selflink *const *bp = b_; - const struct idltest_selflink *a = *ap; - const struct idltest_selflink *b = *bp; - + const struct idltest_link1 *const *ap = a_; + const struct idltest_link1 *const *bp = b_; + const struct idltest_link1 *a = *ap; + const struct idltest_link1 *b = *bp; return a->i < b->i ? -1 : a->i > b->i; } @@ -1247,7 +1246,8 @@ static void print_idl(struct ovsdb_idl *idl, int step) { const struct idltest_simple *s; - const struct idltest_selflink *sl; + const struct idltest_link1 *l1; + const struct idltest_link2 *l2; int n = 0; IDLTEST_SIMPLE_FOR_EACH (s, idl) { @@ -1278,22 +1278,34 @@ print_idl(struct ovsdb_idl *idl, int step) printf("] uuid="UUID_FMT"\n", UUID_ARGS(&s->header_.uuid)); n++; } - IDLTEST_SELFLINK_FOR_EACH (sl, idl) { - struct idltest_selflink **links; + IDLTEST_LINK1_FOR_EACH (l1, idl) { + struct idltest_link1 **links; size_t i; - printf("%03d: i=%"PRId64" k=", step, sl->i); - if (sl->k) { - printf("%"PRId64, sl->k->i); + printf("%03d: i=%"PRId64" k=", step, l1->i); + if (l1->k) { + printf("%"PRId64, l1->k->i); } printf(" ka=["); - links = xmemdup(sl->ka, sl->n_ka * sizeof *sl->ka); - qsort(links, sl->n_ka, sizeof *links, compare_selflink); - for (i = 0; i < sl->n_ka; i++) { + links = xmemdup(l1->ka, l1->n_ka * sizeof *l1->ka); + qsort(links, l1->n_ka, sizeof *links, compare_link1); + for (i = 0; i < l1->n_ka; i++) { printf("%s%"PRId64, i ? " " : "", links[i]->i); } free(links); - printf("] uuid="UUID_FMT"\n", UUID_ARGS(&sl->header_.uuid)); + printf("] l2="); + if (l1->l2) { + printf("%"PRId64, l1->l2->i); + } + printf(" uuid="UUID_FMT"\n", UUID_ARGS(&l1->header_.uuid)); + n++; + } + IDLTEST_LINK2_FOR_EACH (l2, idl) { + printf("%03d: i=%"PRId64" l1=", step, l2->i); + if (l2->l1) { + printf("%"PRId64, l2->l1->i); + } + printf(" uuid="UUID_FMT"\n", UUID_ARGS(&l2->header_.uuid)); n++; } if (!n) { -- 2.30.2