On Wed, Oct 12, 2011 at 10:55:38AM -0700, Ben Pfaff wrote:
> > For vports, if there is no PID we default to using the one associated
> > with the Netlink request.  I'm not sure that that is really all that
> > useful of a feature because it is easy enough for userspace to
> > explicitly set the PID to itself explicitly if that's what it wants
> > but it is inconsistent with this.  I think it would be somewhat
> > difficult to have that behavior here, so should we just make PID
> > mandatory when creating datapaths and vports?
> 
> OK.  I'll send out a separate patch for that.

Here you go.  This is slotted in just after the patch in the subject
header.

Build tested only.

--8<--------------------------cut here-------------------------->8--

From: Ben Pfaff <[email protected]>
Date: Wed, 12 Oct 2011 11:04:10 -0700
Subject: [PATCH] datapath: Require explicit upcall_pid for new datapaths and 
vports.

This increases consistency with the OVS_ACTION_ATTR_USERSPACE action, which
also requires an explicit pid.

Suggested-by: Jesse Gross <[email protected]>
Signed-off-by: Ben Pfaff <[email protected]>
---
 datapath/datapath.c |   15 +++++----------
 lib/dpif-linux.c    |    9 ++++++++-
 2 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/datapath/datapath.c b/datapath/datapath.c
index 551b384..950bed1 100644
--- a/datapath/datapath.c
+++ b/datapath/datapath.c
@@ -1282,7 +1282,7 @@ static int ovs_dp_cmd_new(struct sk_buff *skb, struct 
genl_info *info)
        int err;
 
        err = -EINVAL;
-       if (!a[OVS_DP_ATTR_NAME])
+       if (!a[OVS_DP_ATTR_NAME] || !a[OVS_DP_ATTR_UPCALL_PID])
                goto err;
 
        err = ovs_dp_cmd_validate(a);
@@ -1326,10 +1326,7 @@ static int ovs_dp_cmd_new(struct sk_buff *skb, struct 
genl_info *info)
        parms.options = NULL;
        parms.dp = dp;
        parms.port_no = OVSP_LOCAL;
-       if (a[OVS_DP_ATTR_UPCALL_PID])
-               parms.upcall_pid = nla_get_u32(a[OVS_DP_ATTR_UPCALL_PID]);
-       else
-               parms.upcall_pid = NETLINK_CB(skb).pid;
+       parms.upcall_pid = nla_get_u32(a[OVS_DP_ATTR_UPCALL_PID]);
 
        vport = new_vport(&parms);
        if (IS_ERR(vport)) {
@@ -1664,7 +1661,8 @@ static int ovs_vport_cmd_new(struct sk_buff *skb, struct 
genl_info *info)
        int err;
 
        err = -EINVAL;
-       if (!a[OVS_VPORT_ATTR_NAME] || !a[OVS_VPORT_ATTR_TYPE])
+       if (!a[OVS_VPORT_ATTR_NAME] || !a[OVS_VPORT_ATTR_TYPE] ||
+           !a[OVS_VPORT_ATTR_UPCALL_PID])
                goto exit;
 
        err = ovs_vport_cmd_validate(a);
@@ -1705,10 +1703,7 @@ static int ovs_vport_cmd_new(struct sk_buff *skb, struct 
genl_info *info)
        parms.options = a[OVS_VPORT_ATTR_OPTIONS];
        parms.dp = dp;
        parms.port_no = port_no;
-       if (a[OVS_VPORT_ATTR_UPCALL_PID])
-               parms.upcall_pid = nla_get_u32(a[OVS_VPORT_ATTR_UPCALL_PID]);
-       else
-               parms.upcall_pid = NETLINK_CB(skb).pid;
+       parms.upcall_pid = nla_get_u32(a[OVS_VPORT_ATTR_UPCALL_PID]);
 
        vport = new_vport(&parms);
        err = PTR_ERR(vport);
diff --git a/lib/dpif-linux.c b/lib/dpif-linux.c
index 1e1afe5..08ac442 100644
--- a/lib/dpif-linux.c
+++ b/lib/dpif-linux.c
@@ -235,6 +235,7 @@ dpif_linux_open(const struct dpif_class *class OVS_UNUSED, 
const char *name,
 {
     struct dpif_linux_dp dp_request, dp;
     struct ofpbuf *buf;
+    uint32_t upcall_pid;
     int error;
 
     error = dpif_linux_init();
@@ -244,7 +245,13 @@ dpif_linux_open(const struct dpif_class *class OVS_UNUSED, 
const char *name,
 
     /* Create or look up datapath. */
     dpif_linux_dp_init(&dp_request);
-    dp_request.cmd = create ? OVS_DP_CMD_NEW : OVS_DP_CMD_GET;
+    if (create) {
+        dp_request.cmd = OVS_DP_CMD_NEW;
+        upcall_pid = 0;
+        dp_request.upcall_pid = &upcall_pid;
+    } else {
+        dp_request.cmd = OVS_DP_CMD_GET;
+    }
     dp_request.name = name;
     error = dpif_linux_dp_transact(&dp_request, &dp, &buf);
     if (error) {
-- 
1.7.2.5

_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev

Reply via email to