The ctl_get_row() function attempts to match a user-provided string to a
particular database row. This works by comparing the user-provided
string to the values of columns provided by the ctl utility (e.g.
ovs-vsctl).

Before this commit, this comparison could only be made for columns of
type OVSDB_TYPE_INTEGER and OVSDB_TYPE_STRING. If a ctl utility provided
a column of a different type, then db-ctl-base.c would assert in
get_row_by_id().

This commit enhances the ability of ctl_get_row() to also retrieve rows
based on columns of type OVSDB_TYPE_UUID. The user-provided string is
converted to a UUID and compared against the column's value. If it
matches, then the row matches.

Signed-off-by: Mark Michelson <mmich...@redhat.com>
---
Some context: The OVN southbound database has a Datapath_Binding column
that currently has two external-ids that identify a corresponding
northbound logical datapath by UUID. Being external-ids, the key and
value are both strings.

The `ovn-sbctl lflow-list` command can take an optional argument to narrow the
output to only logical flows for a relevant datapath. The ovn-sbctl utility
uses ctl_get_row() with the user input to find the relevant datapath. A user
can pass the northbound UUID of the relevant datapath, and ctl_get_row() will
find it using one of the external-ids.

An upcoming change in OVN is going to change how the Datapath_Binding
records refer to their corresponding northbound logical datapath UUIDs.
Instead of using external-ids, the value is going to be stored in a
column of type UUID. Therefore, in order to preserve current
functionality in OVN, OVS needs to be able to retrieve the row based on a
column of type UUID. This change helps provide that functionality.
---
 lib/db-ctl-base.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/lib/db-ctl-base.c b/lib/db-ctl-base.c
index 1f157e46c..5b741b1d4 100644
--- a/lib/db-ctl-base.c
+++ b/lib/db-ctl-base.c
@@ -260,6 +260,12 @@ record_id_equals(const union ovsdb_atom *name, enum 
ovsdb_atomic_type type,
         }
 
         return false;
+    } else if (type == OVSDB_TYPE_UUID) {
+        struct uuid record_uuid;
+        if (!uuid_from_string(&record_uuid, record_id)) {
+            return false;
+        }
+        return uuid_equals(&record_uuid, &name->uuid);
     } else {
         ovs_assert(type == OVSDB_TYPE_INTEGER);
         return name->integer == strtoll(record_id, NULL, 10);
@@ -293,12 +299,12 @@ get_row_by_id(struct ctl_context *ctx,
         name_type = value = id->name_column->type.value.type;
     }
 
-    /* We only support integer and string names (so far). */
+    /* We only support integer, UUID, and string names (so far). */
     if (name_type == OVSDB_TYPE_INTEGER) {
         if (!record_id[0] || record_id[strspn(record_id, "0123456789")]) {
             return NULL;
         }
-    } else {
+    } else if (name_type != OVSDB_TYPE_UUID) {
         ovs_assert(name_type == OVSDB_TYPE_STRING);
     }
 
-- 
2.49.0

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

Reply via email to