diff mbox

[ovs-dev,08/27] db-ctl-base: Allow abbreviating UUIDs embedded in strings.

Message ID 20170430232231.15151-9-blp@ovn.org
State Accepted
Headers show

Commit Message

Ben Pfaff April 30, 2017, 11:22 p.m. UTC
This allows commands like "ovn-sbctl lflow-list abcdef" to find a
datapath that has external-ids:logical-switch=abcdef12-3456-...

Signed-off-by: Ben Pfaff <blp@ovn.org>
---
 lib/db-ctl-base.c | 28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)

Comments

Andy Zhou May 3, 2017, 7:19 a.m. UTC | #1
On Sun, Apr 30, 2017 at 4:22 PM, Ben Pfaff <blp@ovn.org> wrote:
> This allows commands like "ovn-sbctl lflow-list abcdef" to find a
> datapath that has external-ids:logical-switch=abcdef12-3456-...
>
> Signed-off-by: Ben Pfaff <blp@ovn.org>

Acked-by: Andy Zhou <azhou@ovn.org>
diff mbox

Patch

diff --git a/lib/db-ctl-base.c b/lib/db-ctl-base.c
index c15e1767b24d..f844a38f65a0 100644
--- a/lib/db-ctl-base.c
+++ b/lib/db-ctl-base.c
@@ -240,6 +240,30 @@  create_symbol(struct ovsdb_symbol_table *symtab, const char *id, bool *newp)
     return symbol;
 }
 
+static bool
+record_id_equals(const union ovsdb_atom *name, enum ovsdb_atomic_type type,
+                 const char *record_id)
+{
+    if (type == OVSDB_TYPE_STRING) {
+        if (!strcmp(name->string, record_id)) {
+            return true;
+        }
+
+        struct uuid uuid;
+        size_t len = strlen(record_id);
+        if (len >= 4
+            && uuid_from_string(&uuid, name->string)
+            && !strncmp(name->string, record_id, len)) {
+            return true;
+        }
+
+        return false;
+    } else {
+        ovs_assert(type == OVSDB_TYPE_INTEGER);
+        return name->integer == strtoll(record_id, NULL, 10);
+    }
+}
+
 static const struct ovsdb_idl_row *
 get_row_by_id(struct ctl_context *ctx,
               const struct ovsdb_idl_table_class *table,
@@ -300,9 +324,7 @@  get_row_by_id(struct ctl_context *ctx,
         }
 
         /* If the name equals 'record_id', take it. */
-        if (name_type == OVSDB_TYPE_STRING
-            ? !strcmp(name->string, record_id)
-            : name->integer == strtoll(record_id, NULL, 10)) {
+        if (record_id_equals(name, name_type, record_id)) {
             if (referrer) {
                 ctl_fatal("multiple rows in %s match \"%s\"",
                           id_table->name, record_id);