From: Ben Pfaff Date: Fri, 5 Aug 2011 21:18:06 +0000 (-0700) Subject: netdev: Get rid of struct netdev_options and netdev_open_default(). X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=18812dff32ce650440b9f1eac1bb00afe08c621a;p=openvswitch netdev: Get rid of struct netdev_options and netdev_open_default(). Now that netdev_options only has two members, we might as well pass them directly as parameters. --- diff --git a/lib/bond.c b/lib/bond.c index 9a13874e..ae914dd9 100644 --- a/lib/bond.c +++ b/lib/bond.c @@ -1507,7 +1507,7 @@ bond_update_fake_slave_stats(struct bond *bond) } } - if (!netdev_open_default(bond->name, &bond_dev)) { + if (!netdev_open(bond->name, "system", &bond_dev)) { netdev_set_stats(bond_dev, &bond_stats); netdev_close(bond_dev); } diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index fa6b5492..9f281c26 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -331,7 +331,6 @@ do_add_port(struct dp_netdev *dp, const char *devname, const char *type, uint16_t port_no) { struct dp_netdev_port *port; - struct netdev_options netdev_options; struct netdev *netdev; bool internal; int mtu; @@ -348,15 +347,13 @@ do_add_port(struct dp_netdev *dp, const char *devname, const char *type, } /* Open and validate network device. */ - memset(&netdev_options, 0, sizeof netdev_options); - netdev_options.name = devname; if (dp->class == &dpif_dummy_class) { - netdev_options.type = "dummy"; + type = "dummy"; } else if (internal) { - netdev_options.type = "tap"; + type = "tap"; } - error = netdev_open(&netdev_options, &netdev); + error = netdev_open(devname, type, &netdev); if (error) { return error; } diff --git a/lib/netdev-vport.c b/lib/netdev-vport.c index fc202328..8e5b5b5a 100644 --- a/lib/netdev-vport.c +++ b/lib/netdev-vport.c @@ -435,7 +435,7 @@ netdev_vport_get_status(const struct netdev *netdev, struct shash *sh) shash_add(sh, "tunnel_egress_iface", xstrdup(iface)); - if (!netdev_open_default(iface, &egress_netdev)) { + if (!netdev_open(iface, "system", &egress_netdev)) { shash_add(sh, "tunnel_egress_iface_carrier", xstrdup(netdev_get_carrier(egress_netdev) ? "up" : "down")); diff --git a/lib/netdev.c b/lib/netdev.c index ec8ae4fc..cd824f84 100644 --- a/lib/netdev.c +++ b/lib/netdev.c @@ -192,14 +192,15 @@ netdev_enumerate_types(struct sset *types) } } -/* Opens the network device named 'name' (e.g. "eth0") and returns zero if - * successful, otherwise a positive errno value. On success, sets '*netdevp' - * to the new network device, otherwise to null. +/* Opens the network device named 'name' (e.g. "eth0") of the specified 'type' + * (e.g. "system") and returns zero if successful, otherwise a positive errno + * value. On success, sets '*netdevp' to the new network device, otherwise to + * null. * * Some network devices may need to be configured (with netdev_set_config()) * before they can be used. */ int -netdev_open(struct netdev_options *options, struct netdev **netdevp) +netdev_open(const char *name, const char *type, struct netdev **netdevp) { struct netdev_dev *netdev_dev; int error; @@ -207,18 +208,18 @@ netdev_open(struct netdev_options *options, struct netdev **netdevp) *netdevp = NULL; netdev_initialize(); - netdev_dev = shash_find_data(&netdev_dev_shash, options->name); + netdev_dev = shash_find_data(&netdev_dev_shash, name); if (!netdev_dev) { const struct netdev_class *class; - class = netdev_lookup_provider(options->type); + class = netdev_lookup_provider(type); if (!class) { VLOG_WARN("could not create netdev %s of unknown type %s", - options->name, options->type); + name, type); return EAFNOSUPPORT; } - error = class->create(class, options->name, &netdev_dev); + error = class->create(class, name, &netdev_dev); if (error) { return error; } @@ -239,17 +240,6 @@ netdev_open(struct netdev_options *options, struct netdev **netdevp) return error; } -int -netdev_open_default(const char *name, struct netdev **netdevp) -{ - struct netdev_options options; - - memset(&options, 0, sizeof options); - options.name = name; - - return netdev_open(&options, netdevp); -} - /* Reconfigures the device 'netdev' with 'args'. 'args' may be empty * or NULL if none are needed. */ int @@ -321,7 +311,7 @@ netdev_exists(const char *name) struct netdev *netdev; int error; - error = netdev_open_default(name, &netdev); + error = netdev_open(name, "system", &netdev); if (!error) { netdev_close(netdev); return true; @@ -1265,7 +1255,7 @@ netdev_find_dev_by_in4(const struct in_addr *in4) SSET_FOR_EACH (name, &dev_list) { struct in_addr dev_in4; - if (!netdev_open_default(name, &netdev) + if (!netdev_open(name, "system", &netdev) && !netdev_get_in4(netdev, &dev_in4, NULL) && dev_in4.s_addr == in4->s_addr) { goto exit; diff --git a/lib/netdev.h b/lib/netdev.h index bcbd8b01..13d2ee76 100644 --- a/lib/netdev.h +++ b/lib/netdev.h @@ -75,11 +75,6 @@ struct netdev_stats { uint64_t tx_window_errors; }; -struct netdev_options { - const char *name; - const char *type; -}; - struct netdev; struct netdev_class; @@ -89,8 +84,7 @@ void netdev_wait(void); void netdev_enumerate_types(struct sset *types); /* Open and close. */ -int netdev_open(struct netdev_options *, struct netdev **); -int netdev_open_default(const char *name, struct netdev **); +int netdev_open(const char *name, const char *type, struct netdev **); void netdev_close(struct netdev *); bool netdev_exists(const char *name); diff --git a/ofproto/in-band.c b/ofproto/in-band.c index 764b2529..f9dd2182 100644 --- a/ofproto/in-band.c +++ b/ofproto/in-band.c @@ -131,7 +131,7 @@ refresh_remote(struct in_band *ib, struct in_band_remote *r) { netdev_close(r->remote_netdev); - retval = netdev_open_default(next_hop_dev, &r->remote_netdev); + retval = netdev_open(next_hop_dev, "system", &r->remote_netdev); if (retval) { VLOG_WARN_RL(&rl, "cannot open netdev %s (next hop " "to controller "IP_FMT"): %s", @@ -472,7 +472,7 @@ in_band_create(struct ofproto *ofproto, const char *local_name, int error; *in_bandp = NULL; - error = netdev_open_default(local_name, &local_netdev); + error = netdev_open(local_name, "system", &local_netdev); if (error) { VLOG_ERR("failed to initialize in-band control: cannot open " "datapath local port %s (%s)", local_name, strerror(error)); diff --git a/ofproto/ofproto-dpif-sflow.c b/ofproto/ofproto-dpif-sflow.c index d2da42b0..303623cd 100644 --- a/ofproto/ofproto-dpif-sflow.c +++ b/ofproto/ofproto-dpif-sflow.c @@ -235,7 +235,7 @@ sflow_choose_agent_address(const char *agent_device, const char *control_ip, if (agent_device) { struct netdev *netdev; - if (!netdev_open_default(agent_device, &netdev)) { + if (!netdev_open(agent_device, "system", &netdev)) { int error = netdev_get_in4(netdev, &in4, NULL); netdev_close(netdev); if (!error) { @@ -337,7 +337,7 @@ dpif_sflow_add_port(struct dpif_sflow *ds, uint16_t odp_port, dpif_sflow_del_port(ds, odp_port); /* Open network device. */ - error = netdev_open_default(netdev_name, &netdev); + error = netdev_open(netdev_name, "system", &netdev); if (error) { VLOG_WARN_RL(&rl, "failed to open network device \"%s\": %s", netdev_name, strerror(error)); diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c index 8054d05c..6203676e 100644 --- a/ofproto/ofproto.c +++ b/ofproto/ofproto.c @@ -1107,16 +1107,11 @@ static struct netdev * ofport_open(const struct ofproto_port *ofproto_port, struct ofp_phy_port *opp) { uint32_t curr, advertised, supported, peer; - struct netdev_options netdev_options; enum netdev_flags flags; struct netdev *netdev; int error; - memset(&netdev_options, 0, sizeof netdev_options); - netdev_options.name = ofproto_port->name; - netdev_options.type = ofproto_port->type; - - error = netdev_open(&netdev_options, &netdev); + error = netdev_open(ofproto_port->name, ofproto_port->type, &netdev); if (error) { VLOG_WARN_RL(&rl, "ignoring port %s (%"PRIu16") because netdev %s " "cannot be opened (%s)", diff --git a/tests/test-openflowd.c b/tests/test-openflowd.c index 2c913108..016e1cbe 100644 --- a/tests/test-openflowd.c +++ b/tests/test-openflowd.c @@ -124,7 +124,7 @@ main(int argc, char *argv[]) SSET_FOR_EACH (port, &s.ports) { struct netdev *netdev; - error = netdev_open_default(port, &netdev); + error = netdev_open(port, "system", &netdev); if (error) { VLOG_FATAL("%s: failed to open network device (%s)", port, strerror(error)); diff --git a/utilities/ovs-dpctl.c b/utilities/ovs-dpctl.c index 3b4749c7..e0848681 100644 --- a/utilities/ovs-dpctl.c +++ b/utilities/ovs-dpctl.c @@ -166,7 +166,7 @@ static int if_up(const char *netdev_name) struct netdev *netdev; int retval; - retval = netdev_open_default(netdev_name, &netdev); + retval = netdev_open(netdev_name, "system", &netdev); if (!retval) { retval = netdev_turn_flags_on(netdev, NETDEV_UP, true); netdev_close(netdev); @@ -222,17 +222,17 @@ do_add_if(int argc OVS_UNUSED, char *argv[]) run(parsed_dpif_open(argv[1], false, &dpif), "opening datapath"); for (i = 2; i < argc; i++) { + const char *name, *type; char *save_ptr = NULL; - struct netdev_options options; struct netdev *netdev = NULL; struct shash args; char *option; int error; - options.name = strtok_r(argv[i], ",", &save_ptr); - options.type = "system"; + name = strtok_r(argv[i], ",", &save_ptr); + type = "system"; - if (!options.name) { + if (!name) { ovs_error(0, "%s is not a valid network device name", argv[i]); continue; } @@ -249,33 +249,31 @@ do_add_if(int argc OVS_UNUSED, char *argv[]) } if (!strcmp(key, "type")) { - options.type = value; + type = value; } else if (!shash_add_once(&args, key, value)) { ovs_error(0, "duplicate \"%s\" option", key); } } - error = netdev_open(&options, &netdev); + error = netdev_open(name, type, &netdev); if (error) { - ovs_error(error, "%s: failed to open network device", - options.name); + ovs_error(error, "%s: failed to open network device", name); goto next; } error = netdev_set_config(netdev, &args); if (error) { - ovs_error(error, "%s: failed to configure network device", - options.name); + ovs_error(error, "%s: failed to configure network device", name); goto next; } error = dpif_port_add(dpif, netdev, NULL); if (error) { - ovs_error(error, "adding %s to %s failed", options.name, argv[1]); + ovs_error(error, "adding %s to %s failed", name, argv[1]); goto next; } - error = if_up(options.name); + error = if_up(name); next: netdev_close(netdev); @@ -383,15 +381,12 @@ show_dpif(struct dpif *dpif) printf("\tport %u: %s", dpif_port.port_no, dpif_port.name); if (strcmp(dpif_port.type, "system")) { - struct netdev_options netdev_options; struct netdev *netdev; int error; printf (" (%s", dpif_port.type); - netdev_options.name = dpif_port.name; - netdev_options.type = dpif_port.type; - error = netdev_open(&netdev_options, &netdev); + error = netdev_open(dpif_port.name, dpif_port.type, &netdev); if (!error) { struct shash config; diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c index ab8527c2..94668a73 100644 --- a/vswitchd/bridge.c +++ b/vswitchd/bridge.c @@ -850,10 +850,7 @@ bridge_add_ofproto_ports(struct bridge *br) /* Open the netdev. */ if (!iface->netdev) { - struct netdev_options options; - options.name = iface->name; - options.type = iface->type; - error = netdev_open(&options, &iface->netdev); + error = netdev_open(iface->name, iface->type, &iface->netdev); if (error) { VLOG_WARN("could not open network device %s (%s)", iface->name, strerror(error)); @@ -928,13 +925,10 @@ bridge_add_ofproto_ports(struct bridge *br) if (port_is_bond_fake_iface(port)) { if (ofproto_port_query_by_name(br->ofproto, port->name, &ofproto_port)) { - struct netdev_options options; struct netdev *netdev; int error; - options.name = port->name; - options.type = "internal"; - error = netdev_open(&options, &netdev); + error = netdev_open(port->name, "internal", &netdev); if (!error) { ofproto_port_add(br->ofproto, netdev, NULL); netdev_close(netdev); diff --git a/vswitchd/ovs-brcompatd.c b/vswitchd/ovs-brcompatd.c index d9b3bc38..c1cc8175 100644 --- a/vswitchd/ovs-brcompatd.c +++ b/vswitchd/ovs-brcompatd.c @@ -488,7 +488,7 @@ handle_fdb_query_cmd(struct ofpbuf *buffer) struct mac *mac = &local_macs[n_local_macs]; struct netdev *netdev; - error = netdev_open_default(iface_name, &netdev); + error = netdev_open(iface_name, "system", &netdev); if (!error) { if (!netdev_get_etheraddr(netdev, mac->addr)) { n_local_macs++;