]> git.proxmox.com Git - mirror_ovs.git/commitdiff
ofproto: Reduce duplication in deletion logic.
authorBen Pfaff <blp@nicira.com>
Thu, 5 Jun 2014 16:58:40 +0000 (09:58 -0700)
committerBen Pfaff <blp@nicira.com>
Thu, 12 Jun 2014 21:46:54 +0000 (14:46 -0700)
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 <blp@nicira.com>
Acked-by: Thomas Graf <tgraf@suug.ch>
Acked-by: Ethan Jackson <ethan@nicira.com>
ofproto/ofproto.c

index 9bee50a68906b2c8d4c1d48b8ae3f35c979aebb4..660c308af80d680df65e09db290e2da48b03f0df 100644 (file)
@@ -222,8 +222,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,
@@ -1165,10 +1166,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'.
@@ -4101,39 +4104,29 @@ modify_flow_strict(struct ofproto *ofproto, struct ofputil_flow_mod *fm,
 \f
 /* 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. */
@@ -4156,7 +4149,7 @@ delete_flows_loose(struct ofproto *ofproto,
     rule_criteria_destroy(&criteria);
 
     if (!error && rules.n > 0) {
-        error = delete_flows__(ofproto, &rules, fm->delete_reason, req);
+        delete_flows__(&rules, fm->delete_reason, req);
     }
     rule_collection_destroy(&rules);
 
@@ -4182,7 +4175,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, fm->delete_reason, req);
+        delete_flows__(&rules, fm->delete_reason, req);
     }
     rule_collection_destroy(&rules);
 
@@ -4905,7 +4898,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. */