From e111e681e36810ac4c5a87c1428ac243ded0ab23 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 14 Jul 2010 17:04:22 -0700 Subject: [PATCH] ovs-vsctl: Do not allow record names to be abbreviated. It's pretty risky to allow record names to be abbreviated. If eth1 through eth20 all exist, and then someone deletes eth1, then until now an ovs-vsctl command that mentioned eth1 would actually use eth10. This is too much of a caveat to let loose on unsuspecting scripts, so this commit removes that functionality. --- tests/ovs-vsctl.at | 5 +---- utilities/ovs-vsctl.8.in | 10 +++------- utilities/ovs-vsctl.c | 43 ++++++++++------------------------------ 3 files changed, 15 insertions(+), 43 deletions(-) diff --git a/tests/ovs-vsctl.at b/tests/ovs-vsctl.at index 4f179b691..fa882b0c7 100644 --- a/tests/ovs-vsctl.at +++ b/tests/ovs-vsctl.at @@ -646,9 +646,6 @@ AT_CHECK([RUN_OVS_VSCTL([list interx x])], AT_CHECK([RUN_OVS_VSCTL([list b x])], [1], [], [ovs-vsctl: no row "x" in table Bridge ], [OVS_VSCTL_CLEANUP]) -AT_CHECK([RUN_OVS_VSCTL([list b br])], - [1], [], [ovs-vsctl: multiple rows in Bridge match "br" -], [OVS_VSCTL_CLEANUP]) AT_CHECK([RUN_OVS_VSCTL([get b br0 d])], [1], [], [ovs-vsctl: Bridge contains more than one column whose name matches "d" ], [OVS_VSCTL_CLEANUP]) @@ -735,7 +732,7 @@ OVS_VSCTL_SETUP # Give the ovs-vsctls a chance to read the database sleep 1 -AT_CHECK([RUN_OVS_VSCTL([add-br br10 -- set bridge br1 other-config:abc=quux]) +AT_CHECK([RUN_OVS_VSCTL([add-br br10 -- set bridge br10 other-config:abc=quux]) RUN_OVS_VSCTL([add-br br1 -- set bridge br1 other-config:abc=def -- add-bond br1 bond0 eth0 eth1 -- set port bond0 bond_updelay=500])], [0], [], [], [OVS_VSCTL_CLEANUP]) diff --git a/utilities/ovs-vsctl.8.in b/utilities/ovs-vsctl.8.in index 50c948234..3137a847e 100644 --- a/utilities/ovs-vsctl.8.in +++ b/utilities/ovs-vsctl.8.in @@ -464,8 +464,9 @@ specifying \fB.\fR as the record name. An sFlow configuration attached to a bridge. Records may be identified by bridge name. .PP -Names of tables, records, and columns are not case-sensitive, and -\fB\-\-\fR and \fB_\fR are treated interchangeably. Unique +Record names must be specified in full and with correct +capitalization. Names of tables and columns are not case-sensitive, +and \fB\-\-\fR and \fB_\fR are treated interchangeably. Unique abbreviations are acceptable, e.g. \fBnet\fR or \fBn\fR is sufficient to identify the \fBNetFlow\fR table. . @@ -601,11 +602,6 @@ whereas \fBget bridge br0 datapath_id \-\- wait\-until bridge br0\fR will abort if no bridge named \fBbr0\fR exists when \fBovs\-vsctl\fR initially connects to the database. .IP -Unlike all the other database commands, \fBwait\-until\fR treats its -\fIrecord\fR argument as case-sensitive and does not allow it to be -abbreviated. Otherwise, \fBwait\-until br1\fR would be satisfied by a -bridge named \fBbr10\fR. -.IP Consider specifying \fB\-\-timeout=0\fR along with \fB\-\-wait\-until\fR, to prevent \fBovs\-vsctl\fR from terminating after waiting only at most 5 seconds. diff --git a/utilities/ovs-vsctl.c b/utilities/ovs-vsctl.c index d9d3b638f..0f8623133 100644 --- a/utilities/ovs-vsctl.c +++ b/utilities/ovs-vsctl.c @@ -1968,8 +1968,7 @@ get_table(const char *table_name) static const struct ovsdb_idl_row * get_row_by_id(struct vsctl_context *ctx, const struct vsctl_table_class *table, - const struct vsctl_row_id *id, const char *record_id, - bool partial_match_ok) + const struct vsctl_row_id *id, const char *record_id) { const struct ovsdb_idl_row *referrer, *final; @@ -1987,35 +1986,24 @@ get_row_by_id(struct vsctl_context *ctx, const struct vsctl_table_class *table, } } else { const struct ovsdb_idl_row *row; - unsigned int best_score = 0; referrer = NULL; for (row = ovsdb_idl_first_row(ctx->idl, id->table); - row != NULL && best_score != UINT_MAX; + row != NULL; row = ovsdb_idl_next_row(row)) { const struct ovsdb_datum *name; name = ovsdb_idl_get(row, id->name_column, OVSDB_TYPE_STRING, OVSDB_TYPE_VOID); - if (name->n == 1) { - unsigned int score; - - score = (partial_match_ok - ? score_partial_match(name->keys[0].string, record_id) - : !strcmp(name->keys[0].string, record_id)); - if (score > best_score) { - referrer = row; - best_score = score; - } else if (score == best_score) { - referrer = NULL; + if (name->n == 1 && !strcmp(name->keys[0].string, record_id)) { + if (referrer) { + vsctl_fatal("multiple rows in %s match \"%s\"", + table->class->name, record_id); } + referrer = row; } } - if (best_score && !referrer) { - vsctl_fatal("multiple rows in %s match \"%s\"", - table->class->name, record_id); - } } if (!referrer) { return NULL; @@ -2039,9 +2027,8 @@ get_row_by_id(struct vsctl_context *ctx, const struct vsctl_table_class *table, } static const struct ovsdb_idl_row * -get_row__(struct vsctl_context *ctx, - const struct vsctl_table_class *table, const char *record_id, - bool partial_match_ok) +get_row (struct vsctl_context *ctx, + const struct vsctl_table_class *table, const char *record_id) { const struct ovsdb_idl_row *row; struct uuid uuid; @@ -2052,8 +2039,7 @@ get_row__(struct vsctl_context *ctx, int i; for (i = 0; i < ARRAY_SIZE(table->row_ids); i++) { - row = get_row_by_id(ctx, table, &table->row_ids[i], record_id, - partial_match_ok); + row = get_row_by_id(ctx, table, &table->row_ids[i], record_id); if (row) { break; } @@ -2062,13 +2048,6 @@ get_row__(struct vsctl_context *ctx, return row; } -static const struct ovsdb_idl_row * -get_row(struct vsctl_context *ctx, - const struct vsctl_table_class *table, const char *record_id) -{ - return get_row__(ctx, table, record_id, true); -} - static const struct ovsdb_idl_row * must_get_row(struct vsctl_context *ctx, const struct vsctl_table_class *table, const char *record_id) @@ -2744,7 +2723,7 @@ cmd_wait_until(struct vsctl_context *ctx) table = get_table(table_name); - row = get_row__(ctx, table, record_id, false); + row = get_row(ctx, table, record_id); if (!row) { ctx->try_again = true; return; -- 2.43.0