From 1e82e503c5358f8dce9eb2105448f0ec894d57bc Mon Sep 17 00:00:00 2001 From: Jesse Gross Date: Tue, 1 Jun 2010 14:20:59 -0700 Subject: [PATCH] netdev: Remove may_create/may_open flags. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The most recent revision of the netdev library added may_create and may_open flags to explicitly state the intent of the caller as to whether the device should already be in use. This was simply a sanity check for users of the netdev library and the configuration. At this point the netdev library and its users are well behaved and should no longer need to be checked. Additional checks have also been added for incorrect configuration that mean the netdev library is no longer the primary line of defense. These flags themselves create problems because it is not always easy for a library to know what the state of devices should be. This is particularly a problem for ovs-openflowd, which expects ports to be added by ovs-dpctl. Fixing this either requires that the checks are so permissive to be useless or ugly hacks to get around them. Since they are no longer needed, just remove the checks. This commit restores the previous behavior of ovs-openflowd to not require that ports be specified on the command line or cleaned up after use. Bug #2652 CC: Natasha Gude CC: Jean Tourrilhes CC: 蒲彦 --- lib/dhcp-client.c | 2 -- lib/dpif-netdev.c | 3 --- lib/netdev.c | 35 ++++++----------------------------- lib/netdev.h | 2 -- ofproto/ofproto.c | 1 - utilities/ovs-openflowd.c | 6 ------ vswitchd/bridge.c | 4 ---- 7 files changed, 6 insertions(+), 47 deletions(-) diff --git a/lib/dhcp-client.c b/lib/dhcp-client.c index 563a415c..709d7a36 100644 --- a/lib/dhcp-client.c +++ b/lib/dhcp-client.c @@ -160,8 +160,6 @@ dhclient_create(const char *netdev_name, memset(&netdev_options, 0, sizeof netdev_options); netdev_options.name = netdev_name; netdev_options.ethertype = ETH_TYPE_IP; - netdev_options.may_create = true; - netdev_options.may_open = true; error = netdev_open(&netdev_options, &netdev); /* XXX install socket filter to catch only DHCP packets. */ diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index c4cc6e98..7b1bb5db 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -375,11 +375,8 @@ do_add_port(struct dp_netdev *dp, const char *devname, uint16_t flags, memset(&netdev_options, 0, sizeof netdev_options); netdev_options.name = devname; netdev_options.ethertype = NETDEV_ETH_TYPE_ANY; - netdev_options.may_create = true; if (internal) { netdev_options.type = "tap"; - } else { - netdev_options.may_open = true; } error = netdev_open(&netdev_options, &netdev); diff --git a/lib/netdev.c b/lib/netdev.c index 0b0463b9..a15315a7 100644 --- a/lib/netdev.c +++ b/lib/netdev.c @@ -265,12 +265,6 @@ create_device(struct netdev_options *options, struct netdev_dev **netdev_devp) { struct netdev_class *netdev_class; - if (!options->may_create) { - VLOG_WARN("attempted to create a device that may not be created: %s", - options->name); - return ENODEV; - } - if (!options->type || strlen(options->type) == 0) { /* Default to system. */ options->type = "system"; @@ -297,15 +291,7 @@ create_device(struct netdev_options *options, struct netdev_dev **netdev_devp) * 'ethertype' may be a 16-bit Ethernet protocol value in host byte order to * capture frames of that type received on the device. It may also be one of * the 'enum netdev_pseudo_ethertype' values to receive frames in one of those - * categories. - * - * If the 'may_create' flag is set then this is allowed to be the first time - * the device is opened (i.e. the refcount will be 1 after this call). It - * may be set to false if the device should have already been created. - * - * If the 'may_open' flag is set then the call will succeed even if another - * caller has already opened it. It may be to false if the device should not - * currently be open. */ + * categories. */ int netdev_open(struct netdev_options *options, struct netdev **netdevp) @@ -330,18 +316,12 @@ netdev_open(struct netdev_options *options, struct netdev **netdevp) } update_device_args(netdev_dev, options->args); - } else if (options->may_open) { - if (!shash_is_empty(options->args) && - !compare_device_args(netdev_dev, options->args)) { + } else if (!shash_is_empty(options->args) && + !compare_device_args(netdev_dev, options->args)) { - VLOG_WARN("%s: attempted to open already created netdev with " - "different arguments", options->name); - return EINVAL; - } - } else { - VLOG_WARN("%s: attempted to create a netdev device with bound name", - options->name); - return EEXIST; + VLOG_WARN("%s: attempted to open already open netdev with " + "different arguments", options->name); + return EINVAL; } error = netdev_dev->netdev_class->open(netdev_dev, options->ethertype, @@ -364,11 +344,8 @@ netdev_open_default(const char *name, struct netdev **netdevp) struct netdev_options options; memset(&options, 0, sizeof options); - options.name = name; options.ethertype = NETDEV_ETH_TYPE_NONE; - options.may_create = true; - options.may_open = true; return netdev_open(&options, netdevp); } diff --git a/lib/netdev.h b/lib/netdev.h index 2a096ee2..5dca24cf 100644 --- a/lib/netdev.h +++ b/lib/netdev.h @@ -85,8 +85,6 @@ struct netdev_options { const char *type; const struct shash *args; int ethertype; - bool may_create; - bool may_open; }; struct netdev; diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c index 7cca951b..9a91c1ce 100644 --- a/ofproto/ofproto.c +++ b/ofproto/ofproto.c @@ -1358,7 +1358,6 @@ make_ofport(const struct odp_port *odp_port) memset(&netdev_options, 0, sizeof netdev_options); netdev_options.name = odp_port->devname; netdev_options.ethertype = NETDEV_ETH_TYPE_NONE; - netdev_options.may_open = true; error = netdev_open(&netdev_options, &netdev); if (error) { diff --git a/utilities/ovs-openflowd.c b/utilities/ovs-openflowd.c index e84a3999..ebfc3c33 100644 --- a/utilities/ovs-openflowd.c +++ b/utilities/ovs-openflowd.c @@ -122,14 +122,8 @@ main(int argc, char *argv[]) if (s.ports.n) { const char *port; size_t i; - struct netdev *netdev; SVEC_FOR_EACH (i, port, &s.ports) { - error = netdev_open_default(port, &netdev); - if (error) { - ovs_fatal(error, "failed to open %s as a device", port); - } - error = dpif_port_add(dpif, port, 0, NULL); if (error) { ovs_fatal(error, "failed to add %s as a port", port); diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c index 61813bb4..931f987c 100644 --- a/vswitchd/bridge.c +++ b/vswitchd/bridge.c @@ -396,10 +396,6 @@ set_up_iface(const struct ovsrec_interface *iface_cfg, struct iface *iface, } netdev_options.args = &options; netdev_options.ethertype = NETDEV_ETH_TYPE_NONE; - netdev_options.may_create = true; - if (iface_is_internal(iface->port->bridge, iface_cfg->name)) { - netdev_options.may_open = true; - } error = netdev_open(&netdev_options, &iface->netdev); -- 2.30.2