As a rule may not be re-inserted to ofproto data structures, it is
cleaner to have three states for the rule, rather than just two.  This
will be useful for managing learned flows in later patches.

Signed-off-by: Jarno Rajahalme <ja...@ovn.org>
---
 ofproto/ofproto-provider.h | 11 +++++++++--
 ofproto/ofproto.c          | 18 +++++++++++-------
 2 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/ofproto/ofproto-provider.h b/ofproto/ofproto-provider.h
index 7f7813e..0013c5d 100644
--- a/ofproto/ofproto-provider.h
+++ b/ofproto/ofproto-provider.h
@@ -323,6 +323,13 @@ struct oftable {
  *      'rule->mutex', and safely written only by coding holding ofproto_mutex
  *      AND 'rule->mutex'.  These are marked OVS_GUARDED.
  */
+enum OVS_PACKED_ENUM rule_state {
+    RULE_INITIALIZED, /* Rule has been initialized, but not inserted to the
+                       * ofproto data structures. */
+    RULE_INSERTED,    /* Rule has been inserted to ofproto data structures. */
+    RULE_REMOVED,     /* Rule has been removed from ofproto data structures. */
+};
+
 struct rule {
     /* Where this rule resides in an OpenFlow switch.
      *
@@ -330,8 +337,6 @@ struct rule {
     struct ofproto *const ofproto; /* The ofproto that contains this rule. */
     const struct cls_rule cr;      /* In owning ofproto's classifier. */
     const uint8_t table_id;        /* Index in ofproto's 'tables' array. */
-    bool removed;                  /* Rule has been removed from the ofproto
-                                    * data structures. */
 
     /* Protects members marked OVS_GUARDED.
      * Readers only need to hold this mutex.
@@ -346,6 +351,8 @@ struct rule {
      * reference. */
     struct ovs_refcount ref_count;
 
+    enum rule_state state OVS_GUARDED;
+
     /* A "flow cookie" is the OpenFlow name for a 64-bit value associated with
      * a flow.. */
     ovs_be64 flow_cookie OVS_GUARDED;
diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c
index 8d90f7e..48d7b8f 100644
--- a/ofproto/ofproto.c
+++ b/ofproto/ofproto.c
@@ -1474,7 +1474,7 @@ ofproto_rule_delete(struct ofproto *ofproto, struct rule 
*rule)
      * be killed. */
     ovs_mutex_lock(&ofproto_mutex);
 
-    if (!rule->removed) {
+    if (rule->state == RULE_INSERTED) {
         /* Make sure there is no postponed removal of the rule. */
         ovs_assert(cls_rule_visible_in_version(&rule->cr, OVS_VERSION_MAX));
 
@@ -4796,7 +4796,7 @@ ofproto_rule_create(struct ofproto *ofproto, struct 
cls_rule *cr,
         return error;
     }
 
-    rule->removed = true;   /* Not yet in ofproto data structures. */
+    rule->state = RULE_INITIALIZED;
 
     *new_rule = rule;
     return 0;
@@ -8074,7 +8074,8 @@ ofproto_rule_insert__(struct ofproto *ofproto, struct 
rule *rule)
 {
     const struct rule_actions *actions = rule_get_actions(rule);
 
-    ovs_assert(rule->removed);
+    /* A rule may not be reinserted. */
+    ovs_assert(rule->state == RULE_INITIALIZED);
 
     if (rule->hard_timeout || rule->idle_timeout) {
         ovs_list_insert(&ofproto->expirable, &rule->expirable);
@@ -8096,8 +8097,9 @@ ofproto_rule_insert__(struct ofproto *ofproto, struct 
rule *rule)
             group_add_rule(group, rule);
         }
     }
-
-    rule->removed = false;
+    ovs_mutex_lock(&rule->mutex);
+    rule->state = RULE_INSERTED;
+    ovs_mutex_unlock(&rule->mutex);
 }
 
 /* Removes 'rule' from the ofproto data structures.  Caller may have deferred
@@ -8106,7 +8108,7 @@ static void
 ofproto_rule_remove__(struct ofproto *ofproto, struct rule *rule)
     OVS_REQUIRES(ofproto_mutex)
 {
-    ovs_assert(!rule->removed);
+    ovs_assert(rule->state == RULE_INSERTED);
 
     cookies_remove(ofproto, rule);
 
@@ -8142,7 +8144,9 @@ ofproto_rule_remove__(struct ofproto *ofproto, struct 
rule *rule)
         }
     }
 
-    rule->removed = true;
+    ovs_mutex_lock(&rule->mutex);
+    rule->state = RULE_REMOVED;
+    ovs_mutex_unlock(&rule->mutex);
 }
 
 /* unixctl commands. */
-- 
2.1.4

_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to