summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJakub Sitnicki <jkbs@redhat.com>2018-07-02 12:50:03 +0200
committerBen Pfaff <blp@ovn.org>2018-07-03 13:19:29 -0700
commit28fcaca6a43bfd34a0b5fc29b04f192c325a9e52 (patch)
tree4d8033094d06f7bb09975b2211702495d20a3208 /lib
parent9065ca453aa33f9271aeba39cfcafa63ff7ae607 (diff)
downloadopenvswitch-28fcaca6a43bfd34a0b5fc29b04f192c325a9e52.tar.gz
db-ctl-base: Don't die in get_row_by_id() on multiple matches.
Signal that multiple rows match the record identifier via a new output parameter instead of reporting the problem and dying, so that the caller can handle the error without terminating the process if needed. Signed-off-by: Jakub Sitnicki <jkbs@redhat.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/db-ctl-base.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/lib/db-ctl-base.c b/lib/db-ctl-base.c
index 61ca1d1b7..00cd2adc6 100644
--- a/lib/db-ctl-base.c
+++ b/lib/db-ctl-base.c
@@ -277,8 +277,11 @@ record_id_equals(const union ovsdb_atom *name, enum ovsdb_atomic_type type,
static const struct ovsdb_idl_row *
get_row_by_id(struct ctl_context *ctx,
const struct ovsdb_idl_table_class *table,
- const struct ctl_row_id *id, const char *record_id)
+ const struct ctl_row_id *id, const char *record_id,
+ bool *multiple_matches)
{
+ ovs_assert(multiple_matches);
+ *multiple_matches = false;
if (!id->name_column) {
return NULL;
@@ -336,8 +339,8 @@ get_row_by_id(struct ctl_context *ctx,
/* If the name equals 'record_id', take it. */
if (record_id_equals(name, name_type, record_id)) {
if (referrer) {
- ctl_fatal("multiple rows in %s match \"%s\"",
- id_table->name, record_id);
+ *multiple_matches = true;
+ return NULL;
}
referrer = row;
}
@@ -386,8 +389,18 @@ ctl_get_row(struct ctl_context *ctx,
const struct ctl_table_class *ctl_class
= &ctl_classes[table - idl_classes];
for (int i = 0; i < ARRAY_SIZE(ctl_class->row_ids); i++) {
- row = get_row_by_id(ctx, table, &ctl_class->row_ids[i],
- record_id);
+ const struct ctl_row_id *id = &ctl_class->row_ids[i];
+ bool multiple_matches;
+
+ row = get_row_by_id(ctx, table, id, record_id, &multiple_matches);
+ if (multiple_matches) {
+ const struct ovsdb_idl_class *class =
+ ovsdb_idl_get_class(ctx->idl);
+ const struct ovsdb_idl_table_class *table_class =
+ ovsdb_idl_table_class_from_column(class, id->name_column);
+ ctl_fatal("multiple rows in %s match \"%s\"",
+ table_class->name, record_id);
+ }
if (row) {
break;
}