diff mbox series

[ovs-dev,branch-20.06,09/15] ofctrl.c: Do not change flow ordering when merging opposite changes.

Message ID 6426f3b116cd53f3a43f143c7103ea21a4361195.1613635760.git.frode.nordahl@canonical.com
State New
Headers show
Series Backport rollup | expand

Commit Message

Dumitru Ceara Oct. 11, 2020, 12:05 p.m. UTC
Instead of removing the old desired flow from the list and inserting the new
one at the end we now directly replace the old flow with the new one while
maintaining the same ordering.

For now order of the flows is not relevant but further commits require
maintaining the order of desired flows.

Signed-off-by: Dumitru Ceara <dceara@redhat.com>
Signed-off-by: Han Zhou <hzhou@ovn.org>
(cherry picked from commit e49ce9a33f38f29c44e3c30afcc189b5f6a9ef8e)
Signed-off-by: Frode Nordahl <frode.nordahl@canonical.com>
---
 controller/ofctrl.c | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/controller/ofctrl.c b/controller/ofctrl.c
index 8404479bc..0262a5cc3 100644
--- a/controller/ofctrl.c
+++ b/controller/ofctrl.c
@@ -848,6 +848,26 @@  link_installed_to_desired(struct installed_flow *i, struct desired_flow *d)
     d->installed_flow = i;
 }
 
+/* Replaces 'old_desired' with 'new_desired' in the list of desired flows
+ * that have same match conditions as the installed flow.
+ *
+ * If 'old_desired' was the active flow, 'new_desired' becomes the active one.
+ */
+static void
+replace_installed_to_desired(struct installed_flow *i,
+                             struct desired_flow *old_desired,
+                             struct desired_flow *new_desired)
+{
+    ovs_assert(old_desired->installed_flow == i);
+    ovs_list_replace(&new_desired->installed_ref_list_node,
+                     &old_desired->installed_ref_list_node);
+    old_desired->installed_flow = NULL;
+    new_desired->installed_flow = i;
+    if (i->desired_flow == old_desired) {
+        i->desired_flow = new_desired;
+    }
+}
+
 static void
 unlink_installed_to_desired(struct installed_flow *i, struct desired_flow *d)
 {
@@ -1843,21 +1863,15 @@  merge_tracked_flows(struct ovn_desired_flow_table *flow_table)
              * removed during track_flow_add_or_modify. */
             ovs_assert(del_f->installed_flow);
 
-            bool del_f_was_active = desired_flow_is_active(del_f);
             if (!f->installed_flow) {
                 /* f is not installed yet. */
-                struct installed_flow *i = del_f->installed_flow;
-                unlink_installed_to_desired(i, del_f);
-                link_installed_to_desired(i, f);
+                replace_installed_to_desired(del_f->installed_flow, del_f, f);
             } else {
                 /* f has been installed before, and now was updated to exact
                  * the same flow as del_f. */
                 ovs_assert(f->installed_flow == del_f->installed_flow);
                 unlink_installed_to_desired(del_f->installed_flow, del_f);
             }
-            if (del_f_was_active) {
-                desired_flow_set_active(f);
-            }
             hmap_remove(&deleted_flows, &del_f->match_hmap_node);
             ovs_list_remove(&del_f->track_list_node);
             desired_flow_destroy(del_f);