summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Pfaff <blp@ovn.org>2017-04-30 14:10:29 -0700
committerBen Pfaff <blp@ovn.org>2017-05-03 08:22:48 -0700
commit61be08e4ed9323d7991c5110ee586608c5cf4bbb (patch)
treed9fd2380ae3987a19fe9e819b5e3837a8a19b6c5
parent2052f3a1d6efb81c93a7ea1db17b4080940cff8f (diff)
downloadopenvswitch-61be08e4ed9323d7991c5110ee586608c5cf4bbb.tar.gz
uuid: New function uuid_is_partial_match().
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>
-rw-r--r--lib/db-ctl-base.c10
-rw-r--r--lib/uuid.c11
-rw-r--r--lib/uuid.h3
3 files changed, 14 insertions, 10 deletions
diff --git a/lib/db-ctl-base.c b/lib/db-ctl-base.c
index ab617f9e0..5ce953659 100644
--- a/lib/db-ctl-base.c
+++ b/lib/db-ctl-base.c
@@ -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 {
diff --git a/lib/uuid.c b/lib/uuid.c
index 636492bcb..06f879259 100644
--- a/lib/uuid.c
+++ b/lib/uuid.c
@@ -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;
+}
static void
sha1_update_int(struct sha1_ctx *sha1_ctx, uintmax_t x)
diff --git a/lib/uuid.h b/lib/uuid.h
index 605ec17b7..10bc8b541 100644
--- a/lib/uuid.h
+++ b/lib/uuid.h
@@ -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 */