ofproto-dpif-xlate: Maintain a pointer to struct dpif.
authorEthan Jackson <ethan@nicira.com>
Sat, 6 Jul 2013 18:46:48 +0000 (11:46 -0700)
committerEthan Jackson <ethan@nicira.com>
Mon, 5 Aug 2013 19:39:48 +0000 (12:39 -0700)
This allows us to move some minor functionality from ofproto-dpif to
ofproto-dpif-xlate, where it's easier to ensure it's thread safe.

Signed-off-by: Ethan Jackson <ethan@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
ofproto/ofproto-dpif-xlate.c
ofproto/ofproto-dpif-xlate.h
ofproto/ofproto-dpif.c
ofproto/ofproto-dpif.h

index fba23cd..808dfb2 100644 (file)
@@ -61,6 +61,7 @@ struct xbridge {
     struct hmap xports;           /* Indexed by ofp_port. */
 
     char *name;                   /* Name used in log messages. */
+    struct dpif *dpif;            /* Datapath interface. */
     struct mac_learning *ml;      /* Mac learning handle. */
     struct mbridge *mbridge;      /* Mirroring. */
     struct dpif_sflow *sflow;     /* SFlow handle, or null. */
@@ -206,8 +207,8 @@ static bool dscp_from_skb_priority(const struct xport *, uint32_t skb_priority,
 
 void
 xlate_ofproto_set(struct ofproto_dpif *ofproto, const char *name,
-                  const struct mac_learning *ml, struct stp *stp,
-                  const struct mbridge *mbridge,
+                  struct dpif *dpif, const struct mac_learning *ml,
+                  struct stp *stp, const struct mbridge *mbridge,
                   const struct dpif_sflow *sflow,
                   const struct dpif_ipfix *ipfix, enum ofp_config_flags frag,
                   bool forward_bpdu, bool has_in_band, bool has_netflow)
@@ -251,6 +252,7 @@ xlate_ofproto_set(struct ofproto_dpif *ofproto, const char *name,
     free(xbridge->name);
     xbridge->name = xstrdup(name);
 
+    xbridge->dpif = dpif;
     xbridge->forward_bpdu = forward_bpdu;
     xbridge->has_in_band = has_in_band;
     xbridge->has_netflow = has_netflow;
@@ -414,9 +416,8 @@ xlate_ofport_set(struct ofproto_dpif *ofproto, struct ofbundle *ofbundle,
         struct skb_priority_to_dscp *pdscp;
         uint32_t skb_priority;
 
-        if (ofproto_dpif_queue_to_priority(xport->xbridge->ofproto,
-                                           qdscp_list[i].queue,
-                                           &skb_priority)) {
+        if (dpif_queue_to_priority(xport->xbridge->dpif, qdscp_list[i].queue,
+                                   &skb_priority)) {
             continue;
         }
 
@@ -1137,15 +1138,19 @@ compose_sample_action(const struct xbridge *xbridge,
                       const size_t cookie_size)
 {
     size_t sample_offset, actions_offset;
+    odp_port_t odp_port;
     int cookie_offset;
+    uint32_t pid;
 
     sample_offset = nl_msg_start_nested(odp_actions, OVS_ACTION_ATTR_SAMPLE);
 
     nl_msg_put_u32(odp_actions, OVS_SAMPLE_ATTR_PROBABILITY, probability);
 
     actions_offset = nl_msg_start_nested(odp_actions, OVS_SAMPLE_ATTR_ACTIONS);
-    cookie_offset = put_userspace_action(xbridge->ofproto, odp_actions, flow,
-                                         cookie, cookie_size);
+
+    odp_port = ofp_port_to_odp_port(xbridge, flow->in_port.ofp_port);
+    pid = dpif_port_get_pid(xbridge->dpif, odp_port);
+    cookie_offset = odp_put_userspace_action(pid, cookie, cookie_size, odp_actions);
 
     nl_msg_end_nested(odp_actions, actions_offset);
     nl_msg_end_nested(odp_actions, sample_offset);
@@ -1810,8 +1815,7 @@ xlate_enqueue_action(struct xlate_ctx *ctx,
     int error;
 
     /* Translate queue to priority. */
-    error = ofproto_dpif_queue_to_priority(ctx->xbridge->ofproto, queue_id,
-                                           &priority);
+    error = dpif_queue_to_priority(ctx->xbridge->dpif, queue_id, &priority);
     if (error) {
         /* Fall back to ordinary output action. */
         xlate_output_action(ctx, enqueue->port, 0, false);
@@ -1844,8 +1848,7 @@ xlate_set_queue_action(struct xlate_ctx *ctx, uint32_t queue_id)
 {
     uint32_t skb_priority;
 
-    if (!ofproto_dpif_queue_to_priority(ctx->xbridge->ofproto, queue_id,
-                                        &skb_priority)) {
+    if (!dpif_queue_to_priority(ctx->xbridge->dpif, queue_id, &skb_priority)) {
         ctx->xin->flow.skb_priority = skb_priority;
     } else {
         /* Couldn't translate queue to a priority.  Nothing to do.  A warning
index 39eb481..befb235 100644 (file)
@@ -24,6 +24,7 @@
 
 struct bfd;
 struct bond;
+struct dpif;
 struct lacp;
 struct dpif_ipfix;
 struct dpif_sflow;
@@ -110,10 +111,11 @@ struct xlate_in {
 };
 
 void xlate_ofproto_set(struct ofproto_dpif *, const char *name,
-                       const struct mac_learning *, struct stp *,
-                       const struct mbridge *, const struct dpif_sflow *,
-                       const struct dpif_ipfix *, enum ofp_config_flags,
-                       bool forward_bpdu, bool has_in_band, bool has_netflow);
+                       struct dpif *, const struct mac_learning *,
+                       struct stp *, const struct mbridge *,
+                       const struct dpif_sflow *, const struct dpif_ipfix *,
+                       enum ofp_config_flags, bool forward_bpdu,
+                       bool has_in_band, bool has_netflow);
 void xlate_remove_ofproto(struct ofproto_dpif *);
 
 void xlate_bundle_set(struct ofproto_dpif *, struct ofbundle *,
index 7425855..d9ff182 100644 (file)
@@ -782,7 +782,8 @@ type_run(const char *type)
                 continue;
             }
 
-            xlate_ofproto_set(ofproto, ofproto->up.name, ofproto->ml,
+            xlate_ofproto_set(ofproto, ofproto->up.name,
+                              ofproto->backer->dpif, ofproto->ml,
                               ofproto->stp, ofproto->mbridge,
                               ofproto->sflow, ofproto->ipfix,
                               ofproto->up.frag_handling,
@@ -2230,13 +2231,6 @@ stp_wait(struct ofproto_dpif *ofproto)
     }
 }
 \f
-int
-ofproto_dpif_queue_to_priority(const struct ofproto_dpif *ofproto,
-                               uint32_t queue_id, uint32_t *priority)
-{
-    return dpif_queue_to_priority(ofproto->backer->dpif, queue_id, priority);
-}
-
 static int
 set_queues(struct ofport *ofport_, const struct ofproto_port_queue *qdscp,
            size_t n_qdscp)
@@ -5382,28 +5376,16 @@ compose_slow_path(const struct ofproto_dpif *ofproto, const struct flow *flow,
                                          ODPP_NONE);
         odp_put_userspace_action(pid, &cookie, sizeof cookie.slow_path, &buf);
     } else {
-        put_userspace_action(ofproto, &buf, flow, &cookie,
-                             sizeof cookie.slow_path);
+        odp_port_t odp_port;
+        uint32_t pid;
+
+        odp_port = ofp_port_to_odp_port(ofproto, flow->in_port.ofp_port);
+        pid = dpif_port_get_pid(ofproto->backer->dpif, odp_port);
+        odp_put_userspace_action(pid, &cookie, sizeof cookie.slow_path, &buf);
     }
     *actionsp = buf.data;
     *actions_lenp = buf.size;
 }
-
-size_t
-put_userspace_action(const struct ofproto_dpif *ofproto,
-                     struct ofpbuf *odp_actions,
-                     const struct flow *flow,
-                     const union user_action_cookie *cookie,
-                     const size_t cookie_size)
-{
-    uint32_t pid;
-
-    pid = dpif_port_get_pid(ofproto->backer->dpif,
-                            ofp_port_to_odp_port(ofproto,
-                                                 flow->in_port.ofp_port));
-
-    return odp_put_userspace_action(pid, cookie, cookie_size, odp_actions);
-}
 \f
 static bool
 set_frag_handling(struct ofproto *ofproto_,
index 6c9afcd..0c6af62 100644 (file)
@@ -61,19 +61,11 @@ struct rule_dpif *rule_dpif_miss_rule(struct ofproto_dpif *ofproto,
 
 void rule_credit_stats(struct rule_dpif *, const struct dpif_flow_stats *);
 
-size_t put_userspace_action(const struct ofproto_dpif *,
-                            struct ofpbuf *odp_actions, const struct flow *,
-                            const union user_action_cookie *,
-                            const size_t cookie_size);
-
 bool ofproto_has_vlan_splinters(const struct ofproto_dpif *);
 ofp_port_t vsp_realdev_to_vlandev(const struct ofproto_dpif *,
                                   ofp_port_t realdev_ofp_port,
                                   ovs_be16 vlan_tci);
 
-int ofproto_dpif_queue_to_priority(const struct ofproto_dpif *,
-                                   uint32_t queue_id, uint32_t *priority);
-
 void ofproto_dpif_send_packet_in(struct ofproto_dpif *,
                                  struct ofputil_packet_in *pin);
 void ofproto_dpif_flow_mod(struct ofproto_dpif *, struct ofputil_flow_mod *);