Provide the ability to determine whether a port exists in a datapath without having to deal with a "dpif_port" structure as with dpif_port_query_by_name(). A future patch will use this function.
Signed-off-by: Justin Pettit <jpet...@nicira.com> --- lib/dpif-linux.c | 2 +- lib/dpif-netdev.c | 4 ++-- lib/dpif-provider.h | 10 ++++++---- lib/dpif.c | 8 ++++++++ lib/dpif.h | 1 + 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/lib/dpif-linux.c b/lib/dpif-linux.c index 6b36ef6..75bfc45 100644 --- a/lib/dpif-linux.c +++ b/lib/dpif-linux.c @@ -492,7 +492,7 @@ dpif_linux_port_query__(const struct dpif *dpif, uint32_t port_no, /* A query by name reported that 'port_name' is in some datapath * other than 'dpif', but the caller wants to know about 'dpif'. */ error = ENODEV; - } else { + } else if (dpif_port) { dpif_port->name = xstrdup(reply.name); dpif_port->type = xstrdup(netdev_vport_get_netdev_type(&reply)); dpif_port->port_no = reply.port_no; diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 5e9be17..3f7685c 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -523,7 +523,7 @@ dpif_netdev_port_query_by_number(const struct dpif *dpif, uint32_t port_no, int error; error = get_port_by_number(dp, port_no, &port); - if (!error) { + if (!error && dpif_port) { answer_port_query(port, dpif_port); } return error; @@ -538,7 +538,7 @@ dpif_netdev_port_query_by_name(const struct dpif *dpif, const char *devname, int error; error = get_port_by_name(dp, devname, &port); - if (!error) { + if (!error && dpif_port) { answer_port_query(port, dpif_port); } return error; diff --git a/lib/dpif-provider.h b/lib/dpif-provider.h index c51b1df..bc18942 100644 --- a/lib/dpif-provider.h +++ b/lib/dpif-provider.h @@ -122,11 +122,13 @@ struct dpif_class { /* Removes port numbered 'port_no' from 'dpif'. */ int (*port_del)(struct dpif *dpif, uint32_t port_no); - /* Queries 'dpif' for a port with the given 'port_no' or 'devname'. Stores - * information about the port into '*port' if successful. + /* Queries 'dpif' for a port with the given 'port_no' or 'devname'. + * If 'port' is not null, stores information about the port into + * '*port' if successful. * - * The caller takes ownership of data in 'port' and must free it with - * dpif_port_destroy() when it is no longer needed. */ + * If 'port' is not null, the caller takes ownership of data in + * 'port' and must free it with dpif_port_destroy() when it is no + * longer needed. */ int (*port_query_by_number)(const struct dpif *dpif, uint32_t port_no, struct dpif_port *port); int (*port_query_by_name)(const struct dpif *dpif, const char *devname, diff --git a/lib/dpif.c b/lib/dpif.c index d8ca061..6bcf46c 100644 --- a/lib/dpif.c +++ b/lib/dpif.c @@ -486,6 +486,14 @@ dpif_port_destroy(struct dpif_port *dpif_port) free(dpif_port->type); } +/* Checks if port named 'devname' exists in 'dpif'. If so, returns + * true; otherwise, returns false. */ +bool +dpif_port_exists(const struct dpif *dpif, const char *devname) +{ + return !dpif->dpif_class->port_query_by_name(dpif, devname, NULL); +} + /* Looks up port number 'port_no' in 'dpif'. On success, returns 0 and * initializes '*port' appropriately; on failure, returns a positive errno * value. diff --git a/lib/dpif.h b/lib/dpif.h index db08d78..bd6095a 100644 --- a/lib/dpif.h +++ b/lib/dpif.h @@ -85,6 +85,7 @@ struct dpif_port { }; void dpif_port_clone(struct dpif_port *, const struct dpif_port *); void dpif_port_destroy(struct dpif_port *); +bool dpif_port_exists(const struct dpif *dpif, const char *devname); int dpif_port_query_by_number(const struct dpif *, uint32_t port_no, struct dpif_port *); int dpif_port_query_by_name(const struct dpif *, const char *devname, -- 1.7.5.4 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev