ovs-vsctl: Make partial matches on record names optional.
authorBen Pfaff <blp@nicira.com>
Thu, 24 Jun 2010 18:16:03 +0000 (11:16 -0700)
committerBen Pfaff <blp@nicira.com>
Tue, 29 Jun 2010 16:33:13 +0000 (09:33 -0700)
The wait-until command to be added to ovs-vsctl in an upcoming commit
doesn't really want to wait for partial matches: if I'm waiting for br1
to be created I really don't want to be fooled by br10.  So this commit
adds infrastructure to avoid such partial matches.

utilities/ovs-vsctl.c

index b7577a0..b5502fd 100644 (file)
@@ -1967,7 +1967,8 @@ 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)
+              const struct vsctl_row_id *id, const char *record_id,
+              bool partial_match_ok)
 {
     const struct ovsdb_idl_row *referrer, *final;
 
@@ -1999,8 +2000,11 @@ get_row_by_id(struct vsctl_context *ctx, const struct vsctl_table_class *table,
 
             ovsdb_idl_txn_read(row, id->name_column, &name);
             if (name.n == 1) {
-                unsigned int score = score_partial_match(name.keys[0].string,
-                                                         record_id);
+                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;
@@ -2040,8 +2044,9 @@ 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)
+get_row__(struct vsctl_context *ctx,
+          const struct vsctl_table_class *table, const char *record_id,
+          bool partial_match_ok)
 {
     const struct ovsdb_idl_row *row;
     struct uuid uuid;
@@ -2052,7 +2057,8 @@ 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);
+            row = get_row_by_id(ctx, table, &table->row_ids[i], record_id,
+                                partial_match_ok);
             if (row) {
                 break;
             }
@@ -2061,6 +2067,13 @@ 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)