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 <b...@ovn.org>
---
 lib/db-ctl-base.c | 28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)

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);
-- 
2.10.2

_______________________________________________
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to