Message ID | 1464294903-26719-3-git-send-email-cascardo@redhat.com |
---|---|
State | Changes Requested |
Headers | show |
On Thu, May 26, 2016 at 05:34:59PM -0300, Thadeu Lima de Souza Cascardo wrote: > If we cannot find the device type because it's not opened yet, check if it uses > a reserved prefix for a vport type and return that type. > > Since these names are reserved, we can assume this is the right type. > > This is important when we are querying the datapath right after vswitch has > started and using the right type will be even more important when we add support > to creating tunnel ports with rtnetlink. > > Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@redhat.com> Thanks for the patch. I haven't thought deeply yet about whether this is correct behavior, but I have some comments nonetheless. > +static const char * > +netdev_vport_type_from_name(const char *name) > +{ > + struct netdev_registered_class *rc; > + const char *type; I don't think we need to take netdev_class_mutex here. cmaps don't inherently need to be protected against change during iteration, because they are RCU-protected. > + ovs_mutex_lock(&netdev_class_mutex); > + CMAP_FOR_EACH (rc, cmap_node, &netdev_classes) { > + const char *dpif_port = netdev_vport_class_get_dpif_port(rc->class); > + if (dpif_port && !strncmp(name, dpif_port, strlen(dpif_port))) { > + type = rc->class->type; > + ovs_mutex_unlock(&netdev_class_mutex); > + return type; > + } > + } > + ovs_mutex_unlock(&netdev_class_mutex); > + return NULL; > +} Here, please do not use the GCC x?:y extension, because OVS needs to build with MSVC as well: > + type = type ?: netdev_vport_type_from_name(name); Thanks, Ben.
diff --git a/lib/netdev.c b/lib/netdev.c index 4be806d..f9325d7 100644 --- a/lib/netdev.c +++ b/lib/netdev.c @@ -281,6 +281,24 @@ netdev_enumerate_types(struct sset *types) } } +static const char * +netdev_vport_type_from_name(const char *name) +{ + struct netdev_registered_class *rc; + const char *type; + ovs_mutex_lock(&netdev_class_mutex); + CMAP_FOR_EACH (rc, cmap_node, &netdev_classes) { + const char *dpif_port = netdev_vport_class_get_dpif_port(rc->class); + if (dpif_port && !strncmp(name, dpif_port, strlen(dpif_port))) { + type = rc->class->type; + ovs_mutex_unlock(&netdev_class_mutex); + return type; + } + } + ovs_mutex_unlock(&netdev_class_mutex); + return NULL; +} + /* Check that the network device name is not the same as any of the registered * vport providers' dpif_port name (dpif_port is NULL if the vport provider * does not define it) or the datapath internal port name (e.g. ovs-system). @@ -1762,6 +1780,7 @@ netdev_get_type_from_name(const char *name) struct netdev *dev = netdev_from_name(name); const char *type = dev ? netdev_get_type(dev) : NULL; netdev_close(dev); + type = type ?: netdev_vport_type_from_name(name); return type; }
If we cannot find the device type because it's not opened yet, check if it uses a reserved prefix for a vport type and return that type. Since these names are reserved, we can assume this is the right type. This is important when we are querying the datapath right after vswitch has started and using the right type will be even more important when we add support to creating tunnel ports with rtnetlink. Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@redhat.com> --- lib/netdev.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)