diff mbox

[ovs-dev] ofproto: Fix consistent hashing

Message ID 1468304140-40876-1-git-send-email-lirans@il.ibm.com
State Accepted
Headers show

Commit Message

Liran Schour July 12, 2016, 6:15 a.m. UTC
Hashing will not be consistent as long as we use for hashing the index of the
bucket in the list (for remove/insert of buckets not from/to the end of the
bucket list).
Use bucket_id for hashing instead.

Signed-off-by: Liran Schour <lirans@il.ibm.com>
---
 ofproto/ofproto-dpif-xlate.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Comments

Simon Horman July 12, 2016, 6:35 a.m. UTC | #1
On Tue, Jul 12, 2016 at 09:15:40AM +0300, Liran Schour wrote:
> Hashing will not be consistent as long as we use for hashing the index of the
> bucket in the list (for remove/insert of buckets not from/to the end of the
> bucket list).
> Use bucket_id for hashing instead.
> 
> Signed-off-by: Liran Schour <lirans@il.ibm.com>

Acked-by: Simon Horman <simon.horman@netronome.com>

> ---
>  ofproto/ofproto-dpif-xlate.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/ofproto/ofproto-dpif-xlate.c b/ofproto/ofproto-dpif-xlate.c
> index 1977b6b..655033d 100644
> --- a/ofproto/ofproto-dpif-xlate.c
> +++ b/ofproto/ofproto-dpif-xlate.c
> @@ -1558,7 +1558,6 @@ group_best_live_bucket(const struct xlate_ctx *ctx,
>  {
>      struct ofputil_bucket *best_bucket = NULL;
>      uint32_t best_score = 0;
> -    int i = 0;
>  
>      struct ofputil_bucket *bucket;
>      const struct ovs_list *buckets;
> @@ -1566,13 +1565,13 @@ group_best_live_bucket(const struct xlate_ctx *ctx,
>      group_dpif_get_buckets(group, &buckets);
>      LIST_FOR_EACH (bucket, list_node, buckets) {
>          if (bucket_is_alive(ctx, bucket, 0)) {
> -            uint32_t score = (hash_int(i, basis) & 0xffff) * bucket->weight;
> +            uint32_t score =
> +                (hash_int(bucket->bucket_id, basis) & 0xffff) * bucket->weight;
>              if (score >= best_score) {
>                  best_bucket = bucket;
>                  best_score = score;
>              }
>          }
> -        i++;
>      }
>  
>      return best_bucket;
> -- 
> 2.1.4
>
Ben Pfaff July 13, 2016, 9:26 p.m. UTC | #2
On Tue, Jul 12, 2016 at 09:15:40AM +0300, Liran Schour wrote:
> Hashing will not be consistent as long as we use for hashing the index of the
> bucket in the list (for remove/insert of buckets not from/to the end of the
> bucket list).
> Use bucket_id for hashing instead.
> 
> Signed-off-by: Liran Schour <lirans@il.ibm.com>

Thanks, applied to master and branch-2.5.

Simon, thanks for reviewing this.
diff mbox

Patch

diff --git a/ofproto/ofproto-dpif-xlate.c b/ofproto/ofproto-dpif-xlate.c
index 1977b6b..655033d 100644
--- a/ofproto/ofproto-dpif-xlate.c
+++ b/ofproto/ofproto-dpif-xlate.c
@@ -1558,7 +1558,6 @@  group_best_live_bucket(const struct xlate_ctx *ctx,
 {
     struct ofputil_bucket *best_bucket = NULL;
     uint32_t best_score = 0;
-    int i = 0;
 
     struct ofputil_bucket *bucket;
     const struct ovs_list *buckets;
@@ -1566,13 +1565,13 @@  group_best_live_bucket(const struct xlate_ctx *ctx,
     group_dpif_get_buckets(group, &buckets);
     LIST_FOR_EACH (bucket, list_node, buckets) {
         if (bucket_is_alive(ctx, bucket, 0)) {
-            uint32_t score = (hash_int(i, basis) & 0xffff) * bucket->weight;
+            uint32_t score =
+                (hash_int(bucket->bucket_id, basis) & 0xffff) * bucket->weight;
             if (score >= best_score) {
                 best_bucket = bucket;
                 best_score = score;
             }
         }
-        i++;
     }
 
     return best_bucket;