The delete_flow__() function had two callers, each of which had to
correctly call ofmonitor_flush() when completely done.  An upcoming commit
will add another function that the callers need to call.  This is easier
if delete_flow__() only has one caller, so this commit refactors so that
it does, and inlines delete_flow__() into that caller for further
simplification.

Also remove a parameter from delete_flows__() that wasn't really needed
and change its return type to void since it can't ever fail.

Signed-off-by: Ben Pfaff <b...@nicira.com>
---
 ofproto/ofproto.c | 61 ++++++++++++++++++++++++-------------------------------
 1 file changed, 27 insertions(+), 34 deletions(-)

diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c
index 5f7f9fb..1ad3ba0 100644
--- a/ofproto/ofproto.c
+++ b/ofproto/ofproto.c
@@ -218,8 +218,9 @@ static enum ofperr add_flow(struct ofproto *, struct 
ofputil_flow_mod *,
 static enum ofperr modify_flows__(struct ofproto *, struct ofputil_flow_mod *,
                                   const struct rule_collection *,
                                   const struct flow_mod_requester *);
-static void delete_flow__(struct rule *, enum ofp_flow_removed_reason,
-                          const struct flow_mod_requester *)
+static void delete_flows__(const struct rule_collection *,
+                           enum ofp_flow_removed_reason,
+                           const struct flow_mod_requester *)
     OVS_REQUIRES(ofproto_mutex);
 
 static enum ofperr send_buffered_packet(struct ofconn *, uint32_t buffer_id,
@@ -1161,10 +1162,12 @@ static void
 ofproto_rule_delete__(struct rule *rule, uint8_t reason)
     OVS_REQUIRES(ofproto_mutex)
 {
-    struct ofproto *ofproto = rule->ofproto;
+    struct rule_collection rules;
 
-    delete_flow__(rule, reason, NULL);
-    ofmonitor_flush(ofproto->connmgr);
+    rules.rules = rules.stub;
+    rules.n = 1;
+    rules.stub[0] = rule;
+    delete_flows__(&rules, reason, NULL);
 }
 
 /* Deletes 'rule' from 'ofproto'.
@@ -4093,39 +4096,29 @@ modify_flow_strict(struct ofproto *ofproto, struct 
ofputil_flow_mod *fm,
 
 /* OFPFC_DELETE implementation. */
 
+/* Deletes the rules listed in 'rules'. */
 static void
-delete_flow__(struct rule *rule, enum ofp_flow_removed_reason reason,
-              const struct flow_mod_requester *req)
-    OVS_REQUIRES(ofproto_mutex)
-{
-    struct ofproto *ofproto = rule->ofproto;
-
-    ofproto_rule_send_removed(rule, reason);
-
-    ofmonitor_report(ofproto->connmgr, rule, NXFME_DELETED, reason,
-                     req ? req->ofconn : NULL, req ? req->xid : 0);
-    oftable_remove_rule(rule);
-    ofproto->ofproto_class->rule_delete(rule);
-}
-
-/* Deletes the rules listed in 'rules'.
- *
- * Returns 0 on success, otherwise an OpenFlow error code. */
-static enum ofperr
-delete_flows__(struct ofproto *ofproto,
-               const struct rule_collection *rules,
+delete_flows__(const struct rule_collection *rules,
                enum ofp_flow_removed_reason reason,
                const struct flow_mod_requester *req)
     OVS_REQUIRES(ofproto_mutex)
 {
-    size_t i;
+    if (rules->n) {
+        struct ofproto *ofproto = rules->rules[0]->ofproto;
+        size_t i;
 
-    for (i = 0; i < rules->n; i++) {
-        delete_flow__(rules->rules[i], reason, req);
-    }
-    ofmonitor_flush(ofproto->connmgr);
+        for (i = 0; i < rules->n; i++) {
+            struct rule *rule = rules->rules[i];
 
-    return 0;
+            ofproto_rule_send_removed(rule, reason);
+
+            ofmonitor_report(ofproto->connmgr, rule, NXFME_DELETED, reason,
+                             req ? req->ofconn : NULL, req ? req->xid : 0);
+            oftable_remove_rule(rule);
+            ofproto->ofproto_class->rule_delete(rule);
+        }
+        ofmonitor_flush(ofproto->connmgr);
+    }
 }
 
 /* Implements OFPFC_DELETE. */
@@ -4148,7 +4141,7 @@ delete_flows_loose(struct ofproto *ofproto,
     rule_criteria_destroy(&criteria);
 
     if (!error && rules.n > 0) {
-        error = delete_flows__(ofproto, &rules, OFPRR_DELETE, req);
+        delete_flows__(&rules, OFPRR_DELETE, req);
     }
     rule_collection_destroy(&rules);
 
@@ -4174,7 +4167,7 @@ delete_flow_strict(struct ofproto *ofproto, const struct 
ofputil_flow_mod *fm,
     rule_criteria_destroy(&criteria);
 
     if (!error && rules.n > 0) {
-        error = delete_flows__(ofproto, &rules, OFPRR_DELETE, req);
+        delete_flows__(&rules, OFPRR_DELETE, req);
     }
     rule_collection_destroy(&rules);
 
@@ -4897,7 +4890,7 @@ handle_delete_meter(struct ofconn *ofconn, struct 
ofputil_meter_mod *mm)
         }
     }
     if (rules.n > 0) {
-        delete_flows__(ofproto, &rules, OFPRR_METER_DELETE, NULL);
+        delete_flows__(&rules, OFPRR_METER_DELETE, NULL);
     }
 
     /* Delete the meters. */
-- 
1.9.1

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

Reply via email to