[ovs-dev] [tunnel 07/11] netdev: New function netdev_get_dpif_port().

Ethan Jackson ethan at nicira.com
Mon Jan 28 00:58:08 UTC 2013


In future patches, a netdev's datapath port name may not
necessarily be the same as its device name. This patch prepares for
this by making the distinction in the netdev and dpif layers.

Signed-off-by: Ethan Jackson <ethan at nicira.com>
---
 lib/dpif-linux.c      |    4 ++--
 lib/dpif-netdev.c     |   17 +++++++++--------
 lib/netdev-dummy.c    |    1 +
 lib/netdev-linux.c    |    1 +
 lib/netdev-provider.h |    5 +++++
 lib/netdev-vport.c    |    1 +
 lib/netdev.c          |   12 +++++++++++-
 lib/netdev.h          |    1 +
 8 files changed, 31 insertions(+), 11 deletions(-)

diff --git a/lib/dpif-linux.c b/lib/dpif-linux.c
index 267f6e7..1c126ad 100644
--- a/lib/dpif-linux.c
+++ b/lib/dpif-linux.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2009, 2010, 2011, 2012 Nicira, Inc.
+ * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -426,7 +426,7 @@ dpif_linux_port_add(struct dpif *dpif_, struct netdev *netdev,
                     uint32_t *port_nop)
 {
     struct dpif_linux *dpif = dpif_linux_cast(dpif_);
-    const char *name = netdev_get_name(netdev);
+    const char *name = netdev_get_dpif_port(netdev);
     const char *type = netdev_get_type(netdev);
     struct dpif_linux_vport request, reply;
     const struct ofpbuf *options;
diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index 2cf2265..bd088c2 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, 2010, 2011, 2012 Nicira, Inc.
+ * Copyright (c) 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -437,11 +437,11 @@ dpif_netdev_port_add(struct dpif *dpif, struct netdev *netdev,
         }
         port_no = *port_nop;
     } else {
-        port_no = choose_port(dp, netdev_get_name(netdev));
+        port_no = choose_port(dp, netdev_get_dpif_port(netdev));
     }
     if (port_no >= 0) {
         *port_nop = port_no;
-        return do_add_port(dp, netdev_get_name(netdev),
+        return do_add_port(dp, netdev_get_dpif_port(netdev),
                            netdev_get_type(netdev), port_no);
     }
     return EFBIG;
@@ -480,7 +480,7 @@ get_port_by_name(struct dp_netdev *dp,
     struct dp_netdev_port *port;
 
     LIST_FOR_EACH (port, node, &dp->port_list) {
-        if (!strcmp(netdev_get_name(port->netdev), devname)) {
+        if (!strcmp(netdev_get_dpif_port(port->netdev), devname)) {
             *portp = port;
             return 0;
         }
@@ -504,7 +504,7 @@ do_del_port(struct dp_netdev *dp, uint32_t port_no)
     dp->ports[port->port_no] = NULL;
     dp->serial++;
 
-    name = xstrdup(netdev_get_name(port->netdev));
+    name = xstrdup(netdev_get_dpif_port(port->netdev));
     netdev_close(port->netdev);
     free(port->type);
 
@@ -518,7 +518,7 @@ static void
 answer_port_query(const struct dp_netdev_port *port,
                   struct dpif_port *dpif_port)
 {
-    dpif_port->name = xstrdup(netdev_get_name(port->netdev));
+    dpif_port->name = xstrdup(netdev_get_dpif_port(port->netdev));
     dpif_port->type = xstrdup(port->type);
     dpif_port->port_no = port->port_no;
 }
@@ -609,7 +609,7 @@ dpif_netdev_port_dump_next(const struct dpif *dpif, void *state_,
         struct dp_netdev_port *port = dp->ports[port_no];
         if (port) {
             free(state->name);
-            state->name = xstrdup(netdev_get_name(port->netdev));
+            state->name = xstrdup(netdev_get_dpif_port(port->netdev));
             dpif_port->name = state->name;
             dpif_port->type = port->type;
             dpif_port->port_no = port->port_no;
@@ -1068,7 +1068,8 @@ dpif_netdev_run(struct dpif *dpif)
         } else if (error != EAGAIN && error != EOPNOTSUPP) {
             static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
             VLOG_ERR_RL(&rl, "error receiving data from %s: %s",
-                        netdev_get_name(port->netdev), strerror(error));
+                        netdev_get_dpif_port(port->netdev),
+                        strerror(error));
         }
     }
     ofpbuf_uninit(&packet);
diff --git a/lib/netdev-dummy.c b/lib/netdev-dummy.c
index ab43772..a3c4f2e 100644
--- a/lib/netdev-dummy.c
+++ b/lib/netdev-dummy.c
@@ -317,6 +317,7 @@ static const struct netdev_class dummy_class = {
 
     netdev_dummy_create,
     netdev_dummy_destroy,
+    NULL,                       /* get_dpif_port. */
     NULL,                       /* get_config */
     NULL,                       /* set_config */
     NULL,                       /* get_tunnel_config */
diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c
index f0f1dc2..a06aef3 100644
--- a/lib/netdev-linux.c
+++ b/lib/netdev-linux.c
@@ -2430,6 +2430,7 @@ netdev_linux_change_seq(const struct netdev *netdev)
                                                                 \
     CREATE,                                                     \
     netdev_linux_destroy,                                       \
+    NULL,                       /* get_dpif_port */             \
     NULL,                       /* get_config */                \
     NULL,                       /* set_config */                \
     NULL,                       /* get_tunnel_config */         \
diff --git a/lib/netdev-provider.h b/lib/netdev-provider.h
index c7de2c2..ce89257 100644
--- a/lib/netdev-provider.h
+++ b/lib/netdev-provider.h
@@ -124,6 +124,11 @@ struct netdev_class {
      * called. */
     void (*destroy)(struct netdev_dev *netdev_dev);
 
+    /* Fetches the dpif port name of 'netdev_dev'. May return null if the
+     * dpif port name is always the same as the device name.  May be null if it
+     * would always return null. */
+    const char *(*get_dpif_port)(struct netdev_dev *netdev_dev);
+
     /* Fetches the device 'netdev_dev''s configuration, storing it in 'args'.
      * The caller owns 'args' and pre-initializes it to an empty smap.
      *
diff --git a/lib/netdev-vport.c b/lib/netdev-vport.c
index cd6ae54..35f2a0c 100644
--- a/lib/netdev-vport.c
+++ b/lib/netdev-vport.c
@@ -848,6 +848,7 @@ patch_get_stats(const struct netdev *netdev, struct netdev_stats *stats)
                                                             \
     netdev_vport_create,                                    \
     netdev_vport_destroy,                                   \
+    NULL,                       /* get_dpif_port */         \
     GET_CONFIG,                                             \
     SET_CONFIG,                                             \
     GET_TUNNEL_CONFIG,                                      \
diff --git a/lib/netdev.c b/lib/netdev.c
index 3909ab2..a18fee5 100644
--- a/lib/netdev.c
+++ b/lib/netdev.c
@@ -1441,7 +1441,6 @@ netdev_get_type(const struct netdev *netdev)
     return netdev_get_dev(netdev)->netdev_class->type;
 }
 
-
 const char *
 netdev_get_type_from_name(const char *name)
 {
@@ -1449,6 +1448,17 @@ netdev_get_type_from_name(const char *name)
     return dev ? netdev_dev_get_type(dev) : NULL;
 }
 
+/* Returns the name of 'netdev''s datapath port. */
+const char *
+netdev_get_dpif_port(const struct netdev *netdev)
+{
+    struct netdev_dev *netdev_dev = netdev_get_dev(netdev);
+    const char *port = netdev_get_dev(netdev)->netdev_class->get_dpif_port
+        ? netdev_get_dev(netdev)->netdev_class->get_dpif_port(netdev_dev)
+        : NULL;
+    return port ? port : netdev_get_name(netdev);
+}
+
 struct netdev_dev *
 netdev_get_dev(const struct netdev *netdev)
 {
diff --git a/lib/netdev.h b/lib/netdev.h
index a691d70..0ccb9c0 100644
--- a/lib/netdev.h
+++ b/lib/netdev.h
@@ -128,6 +128,7 @@ const struct netdev_tunnel_config *
 const char *netdev_get_name(const struct netdev *);
 const char *netdev_get_type(const struct netdev *);
 const char *netdev_get_type_from_name(const char *);
+const char *netdev_get_dpif_port(const struct netdev *);
 int netdev_get_mtu(const struct netdev *, int *mtup);
 int netdev_set_mtu(const struct netdev *, int mtu);
 int netdev_get_ifindex(const struct netdev *);
-- 
1.7.9.5




More information about the dev mailing list