]> git.proxmox.com Git - mirror_ovs.git/commitdiff
uuid: New function uuid_is_partial_match().
authorBen Pfaff <blp@ovn.org>
Sun, 30 Apr 2017 21:10:29 +0000 (14:10 -0700)
committerBen Pfaff <blp@ovn.org>
Wed, 3 May 2017 15:22:48 +0000 (08:22 -0700)
This will have another caller in an upcoming commit.

Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Andy Zhou <azhou@ovn.org>
Acked-by: Russell Bryant <russell@ovn.org>
lib/db-ctl-base.c
lib/uuid.c
lib/uuid.h

index ab617f9e065d06b57711606fbf2b0917f706ef60..5ce953659d33371b4e5bcc7c14a6bf1a3eefbd9d 100644 (file)
@@ -300,14 +300,6 @@ get_row_by_id(struct ctl_context *ctx,
     return final;
 }
 
-static bool
-is_partial_uuid_match(const struct uuid *uuid, const char *match)
-{
-    char uuid_s[UUID_LEN + 1];
-    snprintf(uuid_s, sizeof uuid_s, UUID_FMT, UUID_ARGS(uuid));
-    return !strncmp(uuid_s, match, strlen(match));
-}
-
 static const struct ovsdb_idl_row *
 get_row(struct ctl_context *ctx,
         const struct ovsdb_idl_table_class *table, const char *record_id,
@@ -343,7 +335,7 @@ get_row(struct ctl_context *ctx,
                                                                  table);
              r != NULL;
              r = ovsdb_idl_next_row(r)) {
-            if (is_partial_uuid_match(&r->uuid, record_id)) {
+            if (uuid_is_partial_match(&r->uuid, record_id)) {
                 if (!row) {
                     row = r;
                 } else {
index 636492bcbe5b248e1627cd39db586fc2bcff7ea3..06f8792592d2a69b4f250db8774707407844482d 100644 (file)
@@ -242,6 +242,17 @@ uuid_is_partial_string(const char *s)
     return i;
 }
 
+/* Compares 'match' to the string representation of 'uuid'.  If 'match' equals
+ * or is a prefix of this string representation, returns strlen(match);
+ * otherwise, returns 0. */
+int
+uuid_is_partial_match(const struct uuid *uuid, const char *match)
+{
+    char uuid_s[UUID_LEN + 1];
+    snprintf(uuid_s, sizeof uuid_s, UUID_FMT, UUID_ARGS(uuid));
+    size_t match_len = strlen(match);
+    return !strncmp(uuid_s, match, match_len) ? match_len : 0;
+}
 \f
 static void
 sha1_update_int(struct sha1_ctx *sha1_ctx, uintmax_t x)
index 605ec17b7455040a95c58e858f4aa33694373b16..10bc8b541baccabac348fcbf623ad8ed9e6f1d0f 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2008, 2009, 2010, 2016 Nicira, Inc.
+/* Copyright (c) 2008, 2009, 2010, 2016, 2017 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -65,6 +65,7 @@ int uuid_compare_3way(const struct uuid *, const struct uuid *);
 bool uuid_from_string(struct uuid *, const char *);
 bool uuid_from_string_prefix(struct uuid *, const char *);
 int uuid_is_partial_string(const char *);
+int uuid_is_partial_match(const struct uuid *, const char *match);
 void uuid_set_bits_v4(struct uuid *);
 
 #endif /* uuid.h */