In future patches, a netdev's datapath port name may not necessarily be the same as it's device name. This patch prepares for this by making the distinction in the netdev and dpif layers.
Signed-off-by: Ethan Jackson <et...@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 | 11 +++++++++++ lib/netdev.h | 1 + 8 files changed, 31 insertions(+), 10 deletions(-) diff --git a/lib/dpif-linux.c b/lib/dpif-linux.c index d9dd3b2..19ae565 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. @@ -392,7 +392,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 d042ef9..17fcefd 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. @@ -438,11 +438,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; @@ -481,7 +481,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; } @@ -505,7 +505,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); @@ -519,7 +519,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; } @@ -610,7 +610,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; @@ -1069,7 +1069,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 4e97f55..6740bb8 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 e1936fa..038b85f 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -2431,6 +2431,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 54b3820..e2dfbe9 100644 --- a/lib/netdev-provider.h +++ b/lib/netdev-provider.h @@ -126,6 +126,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 3e0688b..48637d1 100644 --- a/lib/netdev-vport.c +++ b/lib/netdev-vport.c @@ -863,6 +863,7 @@ unparse_patch_config(const char *name OVS_UNUSED, const char *type OVS_UNUSED, \ netdev_vport_create, \ netdev_vport_destroy, \ + NULL, /* get_dpif_port */ \ netdev_vport_get_config, \ netdev_vport_set_config, \ GET_TUNNEL_CONFIG, \ diff --git a/lib/netdev.c b/lib/netdev.c index 057a726..94e3468 100644 --- a/lib/netdev.c +++ b/lib/netdev.c @@ -1442,6 +1442,17 @@ netdev_get_type(const struct netdev *netdev) return netdev_get_dev(netdev)->netdev_class->type; } +/* 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 a544131..942afc6 100644 --- a/lib/netdev.h +++ b/lib/netdev.h @@ -127,6 +127,7 @@ const struct netdev_tunnel_config * /* Basic properties. */ const char *netdev_get_name(const struct netdev *); const char *netdev_get_type(const struct netdev *); +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 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev