From patchwork Wed May 3 02:06:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Zhou X-Patchwork-Id: 757833 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wHhNx60FKz9s3T for ; Wed, 3 May 2017 12:06:57 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id BFA64BC5; Wed, 3 May 2017 02:06:55 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 25B54B9B for ; Wed, 3 May 2017 02:06:54 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 5A94A13A for ; Wed, 3 May 2017 02:06:51 +0000 (UTC) Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by relay8-d.mail.gandi.net (Postfix) with ESMTPS id 1264E40408 for ; Wed, 3 May 2017 04:06:50 +0200 (CEST) Received: from mfilter11-d.gandi.net (mfilter11-d.gandi.net [217.70.178.131]) by relay5-d.mail.gandi.net (Postfix) with ESMTP id 010B841C086 for ; Wed, 3 May 2017 04:06:50 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mfilter11-d.gandi.net Received: from relay5-d.mail.gandi.net ([IPv6:::ffff:217.70.183.197]) by mfilter11-d.gandi.net (mfilter11-d.gandi.net [::ffff:10.0.15.180]) (amavisd-new, port 10024) with ESMTP id HHKzsdgUlidX for ; Wed, 3 May 2017 04:06:48 +0200 (CEST) X-Originating-IP: 209.85.192.175 Received: from mail-pf0-f175.google.com (mail-pf0-f175.google.com [209.85.192.175]) (Authenticated sender: azhou@ovn.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id F1C9B41C07F for ; Wed, 3 May 2017 04:06:47 +0200 (CEST) Received: by mail-pf0-f175.google.com with SMTP id q20so5520516pfg.0 for ; Tue, 02 May 2017 19:06:47 -0700 (PDT) X-Gm-Message-State: AN3rC/6U3YfcycjarBh/qOJgqh0WHjSN3eO54VXi0GE0i1SSOCPFBwt0 vn8YkiVZc7LeBo61x8XakMQv1Wpn1Q== X-Received: by 10.84.254.67 with SMTP id a3mr45870658pln.185.1493777206374; Tue, 02 May 2017 19:06:46 -0700 (PDT) MIME-Version: 1.0 Received: by 10.100.180.134 with HTTP; Tue, 2 May 2017 19:06:06 -0700 (PDT) In-Reply-To: <20170430232231.15151-4-blp@ovn.org> References: <20170430232231.15151-1-blp@ovn.org> <20170430232231.15151-4-blp@ovn.org> From: Andy Zhou Date: Tue, 2 May 2017 19:06:06 -0700 X-Gmail-Original-Message-ID: Message-ID: To: Ben Pfaff X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: "" Subject: Re: [ovs-dev] [PATCH 03/27] uuid: New function uuid_is_partial_match(). X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org On Sun, Apr 30, 2017 at 4:22 PM, Ben Pfaff wrote: > This will have another caller in an upcoming commit. > > Signed-off-by: Ben Pfaff Acked-by: Andy Zhou > --- > lib/db-ctl-base.c | 10 +--------- > lib/uuid.c | 11 +++++++++++ > lib/uuid.h | 3 ++- > 3 files changed, 14 insertions(+), 10 deletions(-) > > diff --git a/lib/db-ctl-base.c b/lib/db-ctl-base.c > index ab617f9e065d..18109691b1d6 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) >= 4) { > if (!row) { > row = r; > } else { > diff --git a/lib/uuid.c b/lib/uuid.c > index 636492bcbe5b..0b20c24faecd 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. (Thus, the caller can */ The last sentence is not finished. > +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; > +} I am not sure if the following optimization makes sense, since the main use case if mainly for match to be << UUID_LEN. On the other hand, it is cheap to check. > > static void > sha1_update_int(struct sha1_ctx *sha1_ctx, uintmax_t x) > diff --git a/lib/uuid.h b/lib/uuid.h > index 605ec17b7455..10bc8b541bac 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 */ > -- > 2.10.2 > > _______________________________________________ > dev mailing list > dev@openvswitch.org > https://mail.openvswitch.org/mailman/listinfo/ovs-dev diff --git a/lib/uuid.c b/lib/uuid.c index 0b20c24faecd..5fa7ed91e852 100644 --- a/lib/uuid.c +++ b/lib/uuid.c @@ -249,8 +249,11 @@ 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); + if (match_len > UUID_LEN) { + return 0; + } + snprintf(uuid_s, sizeof uuid_s, UUID_FMT, UUID_ARGS(uuid)); return !strncmp(uuid_s, match, match_len) ? match_len : 0; }