bbaaef
From 07e82c86d4f6540b701ce43b0c39859a957ab820 Mon Sep 17 00:00:00 2001
bbaaef
From: Dumitru Ceara <dceara@redhat.com>
bbaaef
Date: Mon, 2 Dec 2019 14:20:32 +0100
bbaaef
Subject: [PATCH ovn] ovn-controller: Add missing port group lflow
bbaaef
 references.
bbaaef
bbaaef
The commit that adds incremental processing for port-group changes
bbaaef
doesn't store logical flow references for port groups. If a port group
bbaaef
is updated (e.g., a port is added) no logical flow recalculation will be
bbaaef
performed.
bbaaef
bbaaef
To fix this, when parsing the flow expression also store the referenced
bbaaef
port groups and bind them to the logical flows that depend on them. If
bbaaef
the port group is updated then the logical flows referring them will
bbaaef
also be reinstalled.
bbaaef
bbaaef
Reported-by: Daniel Alvarez <dalvarez@redhat.com>
bbaaef
Reported-at: https://bugzilla.redhat.com/1778164
bbaaef
CC: Han Zhou <hzhou@ovn.org>
bbaaef
Fixes: 978f5e90af0a ("ovn-controller: Incremental processing for port-group changes.")
bbaaef
Tested-By: Daniel Alvarez <dalvarez@redhat.com>
bbaaef
Signed-off-by: Dumitru Ceara <dceara@redhat.com>
bbaaef
Signed-off-by: Han Zhou <hzhou@ovn.org>
bbaaef
bbaaef
(cherry picked from upstream commit bbcac48d443e98cbe47d3941f7e192c9c3443cb5)
bbaaef
---
bbaaef
 include/ovn/expr.h        |  4 +++-
bbaaef
 ovn/controller/lflow.c    |  9 ++++++++-
bbaaef
 ovn/lib/actions.c         |  4 ++--
bbaaef
 ovn/lib/expr.c            | 24 +++++++++++++++++-------
bbaaef
 ovn/utilities/ovn-trace.c |  2 +-
bbaaef
 tests/test-ovn.c          |  8 ++++----
bbaaef
 6 files changed, 35 insertions(+), 16 deletions(-)
bbaaef
bbaaef
diff --git a/include/ovn/expr.h b/include/ovn/expr.h
bbaaef
index 22f633e..21bf51c 100644
bbaaef
--- a/include/ovn/expr.h
bbaaef
+++ b/include/ovn/expr.h
bbaaef
@@ -390,11 +390,13 @@ void expr_print(const struct expr *);
bbaaef
 struct expr *expr_parse(struct lexer *, const struct shash *symtab,
bbaaef
                         const struct shash *addr_sets,
bbaaef
                         const struct shash *port_groups,
bbaaef
-                        struct sset *addr_sets_ref);
bbaaef
+                        struct sset *addr_sets_ref,
bbaaef
+                        struct sset *port_groups_ref);
bbaaef
 struct expr *expr_parse_string(const char *, const struct shash *symtab,
bbaaef
                                const struct shash *addr_sets,
bbaaef
                                const struct shash *port_groups,
bbaaef
                                struct sset *addr_sets_ref,
bbaaef
+                               struct sset *port_groups_ref,
bbaaef
                                char **errorp);
bbaaef
 
bbaaef
 struct expr *expr_clone(struct expr *);
bbaaef
diff --git a/ovn/controller/lflow.c b/ovn/controller/lflow.c
bbaaef
index 9dda76f..9dbce91 100644
bbaaef
--- a/ovn/controller/lflow.c
bbaaef
+++ b/ovn/controller/lflow.c
bbaaef
@@ -616,14 +616,21 @@ consider_logical_flow(
bbaaef
     struct expr *expr;
bbaaef
 
bbaaef
     struct sset addr_sets_ref = SSET_INITIALIZER(&addr_sets_ref);
bbaaef
+    struct sset port_groups_ref = SSET_INITIALIZER(&port_groups_ref);
bbaaef
     expr = expr_parse_string(lflow->match, &symtab, addr_sets, port_groups,
bbaaef
-                             &addr_sets_ref, &error);
bbaaef
+                             &addr_sets_ref, &port_groups_ref, &error);
bbaaef
     const char *addr_set_name;
bbaaef
     SSET_FOR_EACH (addr_set_name, &addr_sets_ref) {
bbaaef
         lflow_resource_add(lfrr, REF_TYPE_ADDRSET, addr_set_name,
bbaaef
                            &lflow->header_.uuid);
bbaaef
     }
bbaaef
+    const char *port_group_name;
bbaaef
+    SSET_FOR_EACH (port_group_name, &port_groups_ref) {
bbaaef
+        lflow_resource_add(lfrr, REF_TYPE_PORTGROUP, port_group_name,
bbaaef
+                           &lflow->header_.uuid);
bbaaef
+    }
bbaaef
     sset_destroy(&addr_sets_ref);
bbaaef
+    sset_destroy(&port_groups_ref);
bbaaef
 
bbaaef
     if (!error) {
bbaaef
         if (prereqs) {
bbaaef
diff --git a/ovn/lib/actions.c b/ovn/lib/actions.c
bbaaef
index 7857f65..82a9334 100644
bbaaef
--- a/ovn/lib/actions.c
bbaaef
+++ b/ovn/lib/actions.c
bbaaef
@@ -240,8 +240,8 @@ add_prerequisite(struct action_context *ctx, const char *prerequisite)
bbaaef
     struct expr *expr;
bbaaef
     char *error;
bbaaef
 
bbaaef
-    expr = expr_parse_string(prerequisite, ctx->pp->symtab, NULL, NULL, NULL,
bbaaef
-                             &error);
bbaaef
+    expr = expr_parse_string(prerequisite, ctx->pp->symtab, NULL, NULL,
bbaaef
+                             NULL, NULL, &error);
bbaaef
     ovs_assert(!error);
bbaaef
     ctx->prereqs = expr_combine(EXPR_T_AND, ctx->prereqs, expr);
bbaaef
 }
bbaaef
diff --git a/ovn/lib/expr.c b/ovn/lib/expr.c
bbaaef
index ca72075..4af1cb2 100644
bbaaef
--- a/ovn/lib/expr.c
bbaaef
+++ b/ovn/lib/expr.c
bbaaef
@@ -480,7 +480,8 @@ struct expr_context {
bbaaef
     const struct shash *symtab;    /* Symbol table. */
bbaaef
     const struct shash *addr_sets; /* Address set table. */
bbaaef
     const struct shash *port_groups; /* Port group table. */
bbaaef
-    struct sset *addr_sets_ref;       /* The set of address set referenced. */
bbaaef
+    struct sset *addr_sets_ref;      /* The set of address set referenced. */
bbaaef
+    struct sset *port_groups_ref;    /* The set of port groups referenced. */
bbaaef
     bool not;                    /* True inside odd number of NOT operators. */
bbaaef
     unsigned int paren_depth;    /* Depth of nested parentheses. */
bbaaef
 };
bbaaef
@@ -782,6 +783,10 @@ static bool
bbaaef
 parse_port_group(struct expr_context *ctx, struct expr_constant_set *cs,
bbaaef
                  size_t *allocated_values)
bbaaef
 {
bbaaef
+    if (ctx->port_groups_ref) {
bbaaef
+        sset_add(ctx->port_groups_ref, ctx->lexer->token.s);
bbaaef
+    }
bbaaef
+
bbaaef
     struct expr_constant_set *port_group
bbaaef
         = (ctx->port_groups
bbaaef
            ? shash_find_data(ctx->port_groups, ctx->lexer->token.s)
bbaaef
@@ -1296,13 +1301,15 @@ struct expr *
bbaaef
 expr_parse(struct lexer *lexer, const struct shash *symtab,
bbaaef
            const struct shash *addr_sets,
bbaaef
            const struct shash *port_groups,
bbaaef
-           struct sset *addr_sets_ref)
bbaaef
+           struct sset *addr_sets_ref,
bbaaef
+           struct sset *port_groups_ref)
bbaaef
 {
bbaaef
     struct expr_context ctx = { .lexer = lexer,
bbaaef
                                 .symtab = symtab,
bbaaef
                                 .addr_sets = addr_sets,
bbaaef
                                 .port_groups = port_groups,
bbaaef
-                                .addr_sets_ref = addr_sets_ref };
bbaaef
+                                .addr_sets_ref = addr_sets_ref,
bbaaef
+                                .port_groups_ref = port_groups_ref };
bbaaef
     return lexer->error ? NULL : expr_parse__(&ctx;;
bbaaef
 }
bbaaef
 
bbaaef
@@ -1317,6 +1324,7 @@ expr_parse_string(const char *s, const struct shash *symtab,
bbaaef
                   const struct shash *addr_sets,
bbaaef
                   const struct shash *port_groups,
bbaaef
                   struct sset *addr_sets_ref,
bbaaef
+                  struct sset *port_groups_ref,
bbaaef
                   char **errorp)
bbaaef
 {
bbaaef
     struct lexer lexer;
bbaaef
@@ -1324,7 +1332,7 @@ expr_parse_string(const char *s, const struct shash *symtab,
bbaaef
     lexer_init(&lexer, s);
bbaaef
     lexer_get(&lexer);
bbaaef
     struct expr *expr = expr_parse(&lexer, symtab, addr_sets, port_groups,
bbaaef
-                                   addr_sets_ref);
bbaaef
+                                   addr_sets_ref, port_groups_ref);
bbaaef
     lexer_force_end(&lexer);
bbaaef
     *errorp = lexer_steal_error(&lexer);
bbaaef
     if (*errorp) {
bbaaef
@@ -1550,7 +1558,8 @@ expr_get_level(const struct expr *expr)
bbaaef
 static enum expr_level
bbaaef
 expr_parse_level(const char *s, const struct shash *symtab, char **errorp)
bbaaef
 {
bbaaef
-    struct expr *expr = expr_parse_string(s, symtab, NULL, NULL, NULL, errorp);
bbaaef
+    struct expr *expr = expr_parse_string(s, symtab, NULL, NULL, NULL, NULL,
bbaaef
+                                          errorp);
bbaaef
     enum expr_level level = expr ? expr_get_level(expr) : EXPR_L_NOMINAL;
bbaaef
     expr_destroy(expr);
bbaaef
     return level;
bbaaef
@@ -1721,7 +1730,7 @@ parse_and_annotate(const char *s, const struct shash *symtab,
bbaaef
     char *error;
bbaaef
     struct expr *expr;
bbaaef
 
bbaaef
-    expr = expr_parse_string(s, symtab, NULL, NULL, NULL, &error);
bbaaef
+    expr = expr_parse_string(s, symtab, NULL, NULL, NULL, NULL, &error);
bbaaef
     if (expr) {
bbaaef
         expr = expr_annotate_(expr, symtab, nesting, &error);
bbaaef
     }
bbaaef
@@ -3445,7 +3454,8 @@ expr_parse_microflow(const char *s, const struct shash *symtab,
bbaaef
     lexer_init(&lexer, s);
bbaaef
     lexer_get(&lexer);
bbaaef
 
bbaaef
-    struct expr *e = expr_parse(&lexer, symtab, addr_sets, port_groups, NULL);
bbaaef
+    struct expr *e = expr_parse(&lexer, symtab, addr_sets, port_groups,
bbaaef
+                                NULL, NULL);
bbaaef
     lexer_force_end(&lexer);
bbaaef
 
bbaaef
     if (e) {
bbaaef
diff --git a/ovn/utilities/ovn-trace.c b/ovn/utilities/ovn-trace.c
bbaaef
index 7ed4a38..05d7113 100644
bbaaef
--- a/ovn/utilities/ovn-trace.c
bbaaef
+++ b/ovn/utilities/ovn-trace.c
bbaaef
@@ -866,7 +866,7 @@ read_flows(void)
bbaaef
         char *error;
bbaaef
         struct expr *match;
bbaaef
         match = expr_parse_string(sblf->match, &symtab, &address_sets,
bbaaef
-                                  &port_groups, NULL, &error);
bbaaef
+                                  &port_groups, NULL, NULL, &error);
bbaaef
         if (error) {
bbaaef
             VLOG_WARN("%s: parsing expression failed (%s)",
bbaaef
                       sblf->match, error);
bbaaef
diff --git a/tests/test-ovn.c b/tests/test-ovn.c
bbaaef
index a7adc1c..b6eea4d 100644
bbaaef
--- a/tests/test-ovn.c
bbaaef
+++ b/tests/test-ovn.c
bbaaef
@@ -289,7 +289,7 @@ test_parse_expr__(int steps)
bbaaef
         char *error;
bbaaef
 
bbaaef
         expr = expr_parse_string(ds_cstr(&input), &symtab, &addr_sets,
bbaaef
-                                 &port_groups, NULL, &error);
bbaaef
+                                 &port_groups, NULL, NULL, &error);
bbaaef
         if (!error && steps > 0) {
bbaaef
             expr = expr_annotate(expr, &symtab, &error);
bbaaef
         }
bbaaef
@@ -413,8 +413,8 @@ test_evaluate_expr(struct ovs_cmdl_context *ctx)
bbaaef
     while (!ds_get_test_line(&input, stdin)) {
bbaaef
         struct expr *expr;
bbaaef
 
bbaaef
-        expr = expr_parse_string(ds_cstr(&input), &symtab, NULL, NULL, NULL,
bbaaef
-                                 &error);
bbaaef
+        expr = expr_parse_string(ds_cstr(&input), &symtab, NULL, NULL,
bbaaef
+                                 NULL, NULL, &error);
bbaaef
         if (!error) {
bbaaef
             expr = expr_annotate(expr, &symtab, &error);
bbaaef
         }
bbaaef
@@ -889,7 +889,7 @@ test_tree_shape_exhaustively(struct expr *expr, struct shash *symtab,
bbaaef
 
bbaaef
             char *error;
bbaaef
             modified = expr_parse_string(ds_cstr(&s), symtab, NULL,
bbaaef
-                                         NULL, NULL, &error);
bbaaef
+                                         NULL, NULL, NULL, &error);
bbaaef
             if (error) {
bbaaef
                 fprintf(stderr, "%s fails to parse (%s)\n",
bbaaef
                         ds_cstr(&s), error);
bbaaef
-- 
bbaaef
1.8.3.1
bbaaef