2
0
mirror of https://github.com/openvswitch/ovs synced 2025-10-17 14:28:02 +00:00

dpif: Add new dpif_port_exists() function.

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 <jpettit@nicira.com>
This commit is contained in:
Justin Pettit
2012-10-17 23:11:53 -07:00
parent 11a574a737
commit 4afba28d55
5 changed files with 24 additions and 7 deletions

View File

@@ -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;

View File

@@ -522,7 +522,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;
@@ -537,7 +537,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;

View File

@@ -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,

View File

@@ -486,6 +486,20 @@ 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)
{
int error = dpif->dpif_class->port_query_by_name(dpif, devname, NULL);
if (error != 0 && error != ENODEV) {
VLOG_WARN_RL(&error_rl, "%s: failed to query port %s: %s",
dpif_name(dpif), devname, strerror(error));
}
return !error;
}
/* Looks up port number 'port_no' in 'dpif'. On success, returns 0 and
* initializes '*port' appropriately; on failure, returns a positive errno
* value.

View File

@@ -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,