[ovs-discuss] [PATCH 07/20] netdev: New function netdev_exists().
Ben Pfaff
blp at nicira.com
Fri Jul 24 21:19:50 UTC 2009
This new function allows cleanup of code that was using
netdev_nodev_get_flags() or ad-hoc methods to detect whether a network
device with the given name exists.
---
lib/netdev.c | 15 +++++++++++++++
lib/netdev.h | 2 ++
vswitchd/ovs-brcompatd.c | 35 ++---------------------------------
3 files changed, 19 insertions(+), 33 deletions(-)
diff --git a/lib/netdev.c b/lib/netdev.c
index 8be1c80..903d14c 100644
--- a/lib/netdev.c
+++ b/lib/netdev.c
@@ -528,6 +528,21 @@ netdev_close(struct netdev *netdev)
}
}
+/* Checks whether a network device named 'name' exists and returns true if so,
+ * false otherwise. */
+bool
+netdev_exists(const char *name)
+{
+ struct stat s;
+ char *filename;
+ int error;
+
+ filename = xasprintf("/sys/class/net/%s", name);
+ error = stat(filename, &s);
+ free(filename);
+ return !error;
+}
+
/* Pads 'buffer' out with zero-bytes to the minimum valid length of an
* Ethernet packet, if necessary. */
static void
diff --git a/lib/netdev.h b/lib/netdev.h
index b37d0af..01eebeb 100644
--- a/lib/netdev.h
+++ b/lib/netdev.h
@@ -77,6 +77,8 @@ struct netdev;
int netdev_open(const char *name, int ethertype, struct netdev **);
void netdev_close(struct netdev *);
+bool netdev_exists(const char *netdev_name);
+
int netdev_recv(struct netdev *, struct ofpbuf *);
void netdev_recv_wait(struct netdev *);
int netdev_drain(struct netdev *);
diff --git a/vswitchd/ovs-brcompatd.c b/vswitchd/ovs-brcompatd.c
index 16fc786..f2e8f12 100644
--- a/vswitchd/ovs-brcompatd.c
+++ b/vswitchd/ovs-brcompatd.c
@@ -272,7 +272,6 @@ static void
prune_ports(void)
{
int i, j;
- int error;
struct svec bridges, delete;
if (cfg_lock(NULL, 0)) {
@@ -291,7 +290,6 @@ prune_ports(void)
get_bridge_ifaces(br_name, &ifaces);
for (j = 0; j < ifaces.n; j++) {
const char *iface_name = ifaces.names[j];
- enum netdev_flags flags;
/* The local port and internal ports are created and destroyed by
* ovs-vswitchd itself, so don't bother checking for them at all.
@@ -302,14 +300,10 @@ prune_ports(void)
continue;
}
- error = netdev_nodev_get_flags(iface_name, &flags);
- if (error == ENODEV) {
+ if (!netdev_exists(iface_name)) {
VLOG_INFO_RL(&rl, "removing dead interface %s from %s",
iface_name, br_name);
svec_add(&delete, iface_name);
- } else if (error) {
- VLOG_INFO_RL(&rl, "unknown error %d on interface %s from %s",
- error, iface_name, br_name);
}
}
svec_destroy(&ifaces);
@@ -331,30 +325,6 @@ prune_ports(void)
svec_destroy(&delete);
}
-
-/* Checks whether a network device named 'name' exists and returns true if so,
- * false otherwise.
- *
- * XXX it is possible that this doesn't entirely accomplish what we want in
- * context, since ovs-vswitchd.conf may cause vswitchd to create or destroy
- * network devices based on iface.*.internal settings.
- *
- * XXX may want to move this to lib/netdev.
- *
- * XXX why not just use netdev_nodev_get_flags() or similar function? */
-static bool
-netdev_exists(const char *name)
-{
- struct stat s;
- char *filename;
- int error;
-
- filename = xasprintf("/sys/class/net/%s", name);
- error = stat(filename, &s);
- free(filename);
- return !error;
-}
-
static int
add_bridge(const char *br_name)
{
@@ -751,7 +721,6 @@ rtnl_recv_update(void)
char br_name[IFNAMSIZ];
uint32_t br_idx = nl_attr_get_u32(attrs[IFLA_MASTER]);
struct svec ports;
- enum netdev_flags flags;
if (!if_indextoname(br_idx, br_name)) {
ofpbuf_delete(buf);
@@ -765,7 +734,7 @@ rtnl_recv_update(void)
return;
}
- if (netdev_nodev_get_flags(port_name, &flags) == ENODEV) {
+ if (!netdev_exists(port_name)) {
/* Network device is really gone. */
VLOG_INFO("network device %s destroyed, "
"removing from bridge %s", port_name, br_name);
--
1.6.3.3
More information about the discuss
mailing list