#include "rtnetlink.h"
#include "rtnetlink-link.h"
#include "shash.h"
+#include "sset.h"
#include "svec.h"
#include "unaligned.h"
#include "util.h"
unsigned int listen_mask;
/* Change notification. */
- struct shash changed_ports; /* Ports that have changed. */
+ struct sset changed_ports; /* Ports that have changed. */
struct rtnetlink_notifier port_notifier;
bool change_error;
};
}
dpif->listen_mask = 0;
dpif->dp_ifindex = dp->dp_ifindex;
- shash_init(&dpif->changed_ports);
+ sset_init(&dpif->changed_ports);
dpif->change_error = false;
*dpifp = &dpif->dpif;
{
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
rtnetlink_link_notifier_unregister(&dpif->port_notifier);
- shash_destroy(&dpif->changed_ports);
+ sset_destroy(&dpif->changed_ports);
free(dpif);
}
if (dpif->change_error) {
dpif->change_error = false;
- shash_clear(&dpif->changed_ports);
+ sset_clear(&dpif->changed_ports);
return ENOBUFS;
- } else if (!shash_is_empty(&dpif->changed_ports)) {
- struct shash_node *node = shash_first(&dpif->changed_ports);
- *devnamep = shash_steal(&dpif->changed_ports, node);
+ } else if (!sset_is_empty(&dpif->changed_ports)) {
+ *devnamep = sset_pop(&dpif->changed_ports);
return 0;
} else {
return EAGAIN;
dpif_linux_port_poll_wait(const struct dpif *dpif_)
{
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
- if (!shash_is_empty(&dpif->changed_ports) || dpif->change_error) {
+ if (!sset_is_empty(&dpif->changed_ports) || dpif->change_error) {
poll_immediate_wake();
} else {
rtnetlink_link_notifier_wait();
{
/* Our datapath changed, either adding a new port or deleting an
* existing one. */
- shash_add_once(&dpif->changed_ports, change->ifname, NULL);
+ sset_add(&dpif->changed_ports, change->ifname);
}
} else {
dpif->change_error = true;
/*
- * Copyright (c) 2008, 2009, 2010 Nicira Networks.
+ * Copyright (c) 2008, 2009, 2010, 2011 Nicira Networks.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <unistd.h>
#include "poll-loop.h"
#include "shash.h"
+#include "sset.h"
#include "socket-util.h"
#include "util.h"
#include "vlog.h"
}
}
\f
-/* Files to delete on exit. (The 'data' member of each node is unused.) */
-static struct shash files = SHASH_INITIALIZER(&files);
+/* Files to delete on exit. */
+static struct sset files = SSET_INITIALIZER(&files);
/* Has a hook function been registered with fatal_signal_add_hook() (and not
* cleared by fatal_signal_fork())? */
fatal_signal_add_hook(unlink_files, cancel_files, NULL, true);
}
- shash_add_once(&files, file, NULL);
+ sset_add(&files, file);
}
/* Unregisters 'file' from being unlinked when the program terminates via
void
fatal_signal_remove_file_to_unlink(const char *file)
{
- struct shash_node *node;
-
- node = shash_find(&files, file);
- if (node) {
- shash_delete(&files, node);
- }
+ sset_find_and_delete(&files, file);
}
/* Like fatal_signal_remove_file_to_unlink(), but also unlinks 'file'.
static void
cancel_files(void *aux OVS_UNUSED)
{
- shash_clear(&files);
+ sset_clear(&files);
added_hook = false;
}
static void
do_unlink_files(void)
{
- struct shash_node *node;
+ const char *file;
- SHASH_FOR_EACH (node, &files) {
- unlink(node->name);
+ SSET_FOR_EACH (file, &files) {
+ unlink(file);
}
}
\f
#include "packets.h"
#include "poll-loop.h"
#include "shash.h"
+#include "sset.h"
#include "svec.h"
#include "vlog.h"
/* Tracks changes in the status of a set of network devices. */
struct netdev_monitor {
struct shash polled_netdevs;
- struct shash changed_netdevs;
+ struct sset changed_netdevs;
};
/* Creates and returns a new structure for monitor changes in the status of
{
struct netdev_monitor *monitor = xmalloc(sizeof *monitor);
shash_init(&monitor->polled_netdevs);
- shash_init(&monitor->changed_netdevs);
+ sset_init(&monitor->changed_netdevs);
return monitor;
}
}
shash_destroy(&monitor->polled_netdevs);
- shash_destroy(&monitor->changed_netdevs);
+ sset_destroy(&monitor->changed_netdevs);
free(monitor);
}
}
{
struct netdev_monitor *monitor = notifier->aux;
const char *name = netdev_get_name(notifier->netdev);
- shash_add_once(&monitor->changed_netdevs, name, NULL);
+ sset_add(&monitor->changed_netdevs, name);
}
/* Attempts to add 'netdev' as a netdev monitored by 'monitor'. Returns 0 if
shash_delete(&monitor->polled_netdevs, node);
/* Drop any pending notification. */
- node = shash_find(&monitor->changed_netdevs, netdev_name);
- if (node) {
- shash_delete(&monitor->changed_netdevs, node);
- }
+ sset_find_and_delete(&monitor->changed_netdevs, netdev_name);
}
}
int
netdev_monitor_poll(struct netdev_monitor *monitor, char **devnamep)
{
- struct shash_node *node = shash_first(&monitor->changed_netdevs);
- if (!node) {
+ if (sset_is_empty(&monitor->changed_netdevs)) {
*devnamep = NULL;
return EAGAIN;
} else {
- *devnamep = shash_steal(&monitor->changed_netdevs, node);
+ *devnamep = sset_pop(&monitor->changed_netdevs);
return 0;
}
}
void
netdev_monitor_poll_wait(const struct netdev_monitor *monitor)
{
- if (!shash_is_empty(&monitor->changed_netdevs)) {
+ if (!sset_is_empty(&monitor->changed_netdevs)) {
poll_immediate_wake();
} else {
/* XXX Nothing needed here for netdev_linux, but maybe other netdev
#include "poll-loop.h"
#include "rconn.h"
#include "shash.h"
+#include "sset.h"
#include "stream-ssl.h"
#include "svec.h"
#include "tag.h"
reinit_ports(struct ofproto *p)
{
struct dpif_port_dump dump;
- struct shash_node *node;
- struct shash devnames;
+ struct sset devnames;
struct ofport *ofport;
struct dpif_port dpif_port;
+ const char *devname;
COVERAGE_INC(ofproto_reinit_ports);
- shash_init(&devnames);
+ sset_init(&devnames);
HMAP_FOR_EACH (ofport, hmap_node, &p->ports) {
- shash_add_once (&devnames, ofport->opp.name, NULL);
+ sset_add(&devnames, ofport->opp.name);
}
DPIF_PORT_FOR_EACH (&dpif_port, &dump, p->dpif) {
- shash_add_once (&devnames, dpif_port.name, NULL);
+ sset_add(&devnames, dpif_port.name);
}
- SHASH_FOR_EACH (node, &devnames) {
- update_port(p, node->name);
+ SSET_FOR_EACH (devname, &devnames) {
+ update_port(p, devname);
}
- shash_destroy(&devnames);
+ sset_destroy(&devnames);
}
static struct ofport *
#include "stream-ssl.h"
#include "stream.h"
#include "stress.h"
-#include "svec.h"
+#include "sset.h"
#include "table.h"
#include "timeval.h"
#include "transaction.h"
static unixctl_cb_func ovsdb_server_reconnect;
static void parse_options(int argc, char *argv[], char **file_namep,
- struct shash *remotes, char **unixctl_pathp,
+ struct sset *remotes, char **unixctl_pathp,
char **run_command);
static void usage(void) NO_RETURN;
static void reconfigure_from_db(struct ovsdb_jsonrpc_server *jsonrpc,
- const struct ovsdb *db, struct shash *remotes);
+ const struct ovsdb *db, struct sset *remotes);
static void update_remote_status(const struct ovsdb_jsonrpc_server *jsonrpc,
- const struct shash *remotes,
+ const struct sset *remotes,
struct ovsdb *db);
int
char *run_command = NULL;
struct unixctl_server *unixctl;
struct ovsdb_jsonrpc_server *jsonrpc;
- struct shash remotes;
+ struct sset remotes;
struct ovsdb_error *error;
struct ovsdb_file *file;
struct ovsdb *db;
}
ovsdb_jsonrpc_server_destroy(jsonrpc);
ovsdb_destroy(db);
- shash_destroy_free_data(&remotes);
+ sset_destroy(&remotes);
unixctl_server_destroy(unixctl);
if (run_process && process_exited(run_process)) {
static void
update_remote_status(const struct ovsdb_jsonrpc_server *jsonrpc,
- const struct shash *remotes, struct ovsdb *db)
+ const struct sset *remotes, struct ovsdb *db)
{
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
- struct shash_node *remote;
struct shash statuses;
struct ovsdb_txn *txn;
const bool durable_txn = false;
struct ovsdb_error *error;
+ const char *remote;
/* Get status of current connections. */
ovsdb_jsonrpc_server_get_remote_status(jsonrpc, &statuses);
txn = ovsdb_txn_create(db);
/* Iterate over --remote arguments given on command line. */
- SHASH_FOR_EACH (remote, remotes) {
- update_remote_rows(db, txn, remote->name, &statuses);
+ SSET_FOR_EACH (remote, remotes) {
+ update_remote_rows(db, txn, remote, &statuses);
}
error = ovsdb_txn_commit(txn, durable_txn);
/* Reconfigures ovsdb-server based on information in the database. */
static void
reconfigure_from_db(struct ovsdb_jsonrpc_server *jsonrpc,
- const struct ovsdb *db, struct shash *remotes)
+ const struct ovsdb *db, struct sset *remotes)
{
struct shash resolved_remotes;
- struct shash_node *node;
+ const char *name;
/* Configure remotes. */
shash_init(&resolved_remotes);
- SHASH_FOR_EACH (node, remotes) {
- const char *name = node->name;
-
+ SSET_FOR_EACH (name, remotes) {
if (!strncmp(name, "db:", 3)) {
query_db_remotes(name, db, &resolved_remotes);
} else {
static void
parse_options(int argc, char *argv[], char **file_namep,
- struct shash *remotes, char **unixctl_pathp,
+ struct sset *remotes, char **unixctl_pathp,
char **run_command)
{
enum {
};
char *short_options = long_options_to_short_options(long_options);
- shash_init(remotes);
+ sset_init(remotes);
for (;;) {
int c;
switch (c) {
case OPT_REMOTE:
- shash_add_once(remotes, optarg, NULL);
+ sset_add(remotes, optarg);
break;
case OPT_UNIXCTL:
#include "process.h"
#include "stream.h"
#include "stream-ssl.h"
+#include "sset.h"
#include "svec.h"
#include "vswitchd/vswitch-idl.h"
#include "table.h"
get_info(struct vsctl_context *ctx, struct vsctl_info *info)
{
const struct ovsrec_open_vswitch *ovs = ctx->ovs;
- struct shash bridges, ports;
+ struct sset bridges, ports;
size_t i;
info->ctx = ctx;
shash_init(&info->ports);
shash_init(&info->ifaces);
- shash_init(&bridges);
- shash_init(&ports);
+ sset_init(&bridges);
+ sset_init(&ports);
for (i = 0; i < ovs->n_bridges; i++) {
struct ovsrec_bridge *br_cfg = ovs->bridges[i];
struct vsctl_bridge *br;
size_t j;
- if (!shash_add_once(&bridges, br_cfg->name, NULL)) {
+ if (!sset_add(&bridges, br_cfg->name)) {
VLOG_WARN("%s: database contains duplicate bridge name",
br_cfg->name);
continue;
for (j = 0; j < br_cfg->n_ports; j++) {
struct ovsrec_port *port_cfg = br_cfg->ports[j];
- if (!shash_add_once(&ports, port_cfg->name, NULL)) {
+ if (!sset_add(&ports, port_cfg->name)) {
VLOG_WARN("%s: database contains duplicate port name",
port_cfg->name);
continue;
}
if (port_is_fake_bridge(port_cfg)
- && shash_add_once(&bridges, port_cfg->name, NULL)) {
+ && sset_add(&bridges, port_cfg->name)) {
add_bridge(info, NULL, port_cfg->name, br, *port_cfg->tag);
}
}
}
- shash_destroy(&bridges);
- shash_destroy(&ports);
+ sset_destroy(&bridges);
+ sset_destroy(&ports);
- shash_init(&bridges);
- shash_init(&ports);
+ sset_init(&bridges);
+ sset_init(&ports);
for (i = 0; i < ovs->n_bridges; i++) {
struct ovsrec_bridge *br_cfg = ovs->bridges[i];
struct vsctl_bridge *br;
size_t j;
- if (!shash_add_once(&bridges, br_cfg->name, NULL)) {
+ if (!sset_add(&bridges, br_cfg->name)) {
continue;
}
br = shash_find_data(&info->bridges, br_cfg->name);
struct vsctl_port *port;
size_t k;
- if (!shash_add_once(&ports, port_cfg->name, NULL)) {
+ if (!sset_add(&ports, port_cfg->name)) {
continue;
}
if (port_is_fake_bridge(port_cfg)
- && !shash_add_once(&bridges, port_cfg->name, NULL)) {
+ && !sset_add(&bridges, port_cfg->name)) {
continue;
}
}
}
}
- shash_destroy(&bridges);
- shash_destroy(&ports);
+ sset_destroy(&bridges);
+ sset_destroy(&ports);
}
static void
#include "shash.h"
#include "socket-util.h"
#include "stream-ssl.h"
+#include "sset.h"
#include "svec.h"
#include "system-stats.h"
#include "timeval.h"
struct uuid uuid; /* UUID of this "mirror" record in database. */
/* Selection criteria. */
- struct shash src_ports; /* Name is port name; data is always NULL. */
- struct shash dst_ports; /* Name is port name; data is always NULL. */
+ struct sset src_ports; /* Source port names. */
+ struct sset dst_ports; /* Destination port names. */
int *vlans;
size_t n_vlans;
{
struct sockaddr_in *managers = NULL;
size_t n_managers = 0;
- struct shash targets;
+ struct sset targets;
size_t i;
/* Collect all of the potential targets from the "targets" columns of the
* rows pointed to by "manager_options", excluding any that are
* out-of-band. */
- shash_init(&targets);
+ sset_init(&targets);
for (i = 0; i < ovs_cfg->n_manager_options; i++) {
struct ovsrec_manager *m = ovs_cfg->manager_options[i];
if (m->connection_mode && !strcmp(m->connection_mode, "out-of-band")) {
- shash_find_and_delete(&targets, m->target);
+ sset_find_and_delete(&targets, m->target);
} else {
- shash_add_once(&targets, m->target, NULL);
+ sset_add(&targets, m->target);
}
}
/* Now extract the targets' IP addresses. */
- if (!shash_is_empty(&targets)) {
- struct shash_node *node;
+ if (!sset_is_empty(&targets)) {
+ const char *target;
- managers = xmalloc(shash_count(&targets) * sizeof *managers);
- SHASH_FOR_EACH (node, &targets) {
- const char *target = node->name;
+ managers = xmalloc(sset_count(&targets) * sizeof *managers);
+ SSET_FOR_EACH (target, &targets) {
struct sockaddr_in *sin = &managers[n_managers];
if ((!strncmp(target, "tcp:", 4)
}
}
}
- shash_destroy(&targets);
+ sset_destroy(&targets);
*managersp = managers;
*n_managersp = n_managers;
port_del_ifaces(struct port *port, const struct ovsrec_port *cfg)
{
struct iface *iface, *next;
- struct shash new_ifaces;
+ struct sset new_ifaces;
size_t i;
/* Collect list of new interfaces. */
- shash_init(&new_ifaces);
+ sset_init(&new_ifaces);
for (i = 0; i < cfg->n_interfaces; i++) {
const char *name = cfg->interfaces[i]->name;
- shash_add_once(&new_ifaces, name, NULL);
+ sset_add(&new_ifaces, name);
}
/* Get rid of deleted interfaces. */
LIST_FOR_EACH_SAFE (iface, next, port_elem, &port->ifaces) {
- if (!shash_find(&new_ifaces, iface->name)) {
+ if (!sset_contains(&new_ifaces, iface->name)) {
iface_destroy(iface);
}
}
- shash_destroy(&new_ifaces);
+ sset_destroy(&new_ifaces);
}
/* Expires all MAC learning entries associated with 'port' and forces ofproto
port_reconfigure(struct port *port, const struct ovsrec_port *cfg)
{
const char *detect_mode;
- struct shash new_ifaces;
+ struct sset new_ifaces;
long long int next_rebalance, miimon_next_update, lacp_priority;
bool need_flush = false;
unsigned long *trunks;
}
/* Add new interfaces and update 'cfg' member of existing ones. */
- shash_init(&new_ifaces);
+ sset_init(&new_ifaces);
for (i = 0; i < cfg->n_interfaces; i++) {
const struct ovsrec_interface *if_cfg = cfg->interfaces[i];
struct iface *iface;
- if (!shash_add_once(&new_ifaces, if_cfg->name, NULL)) {
+ if (!sset_add(&new_ifaces, if_cfg->name)) {
VLOG_WARN("port %s: %s specified twice as port interface",
port->name, if_cfg->name);
iface_set_ofport(if_cfg, -1);
iface->lacp_priority = lacp_priority;
}
}
- shash_destroy(&new_ifaces);
+ sset_destroy(&new_ifaces);
port->lacp_fast = !strcmp(get_port_other_config(cfg, "lacp-time", "slow"),
"fast");
m->bridge = br;
m->idx = i;
m->name = xstrdup(cfg->name);
- shash_init(&m->src_ports);
- shash_init(&m->dst_ports);
+ sset_init(&m->src_ports);
+ sset_init(&m->dst_ports);
m->vlans = NULL;
m->n_vlans = 0;
m->out_vlan = -1;
port->dst_mirrors &= ~(MIRROR_MASK_C(1) << m->idx);
}
- shash_destroy(&m->src_ports);
- shash_destroy(&m->dst_ports);
+ sset_destroy(&m->src_ports);
+ sset_destroy(&m->dst_ports);
free(m->vlans);
m->bridge->mirrors[m->idx] = NULL;
static void
mirror_collect_ports(struct mirror *m, struct ovsrec_port **ports, int n_ports,
- struct shash *names)
+ struct sset *names)
{
size_t i;
for (i = 0; i < n_ports; i++) {
const char *name = ports[i]->name;
if (port_lookup(m->bridge, name)) {
- shash_add_once(names, name, NULL);
+ sset_add(names, name);
} else {
VLOG_WARN("bridge %s: mirror %s cannot match on nonexistent "
"port %s", m->bridge->name, m->name, name);
static void
mirror_reconfigure_one(struct mirror *m, struct ovsrec_mirror *cfg)
{
- struct shash src_ports, dst_ports;
+ struct sset src_ports, dst_ports;
mirror_mask_t mirror_bit;
struct port *out_port;
struct port *port;
return;
}
- shash_init(&src_ports);
- shash_init(&dst_ports);
+ sset_init(&src_ports);
+ sset_init(&dst_ports);
if (cfg->select_all) {
HMAP_FOR_EACH (port, hmap_node, &m->bridge->ports) {
- shash_add_once(&src_ports, port->name, NULL);
- shash_add_once(&dst_ports, port->name, NULL);
+ sset_add(&src_ports, port->name);
+ sset_add(&dst_ports, port->name);
}
vlans = NULL;
n_vlans = 0;
}
/* Update mirror data. */
- if (!shash_equal_keys(&m->src_ports, &src_ports)
- || !shash_equal_keys(&m->dst_ports, &dst_ports)
+ if (!sset_equals(&m->src_ports, &src_ports)
+ || !sset_equals(&m->dst_ports, &dst_ports)
|| m->n_vlans != n_vlans
|| memcmp(m->vlans, vlans, sizeof *vlans * n_vlans)
|| m->out_port != out_port
bridge_flush(m->bridge);
mac_learning_flush(m->bridge->ml);
}
- shash_swap(&m->src_ports, &src_ports);
- shash_swap(&m->dst_ports, &dst_ports);
+ sset_swap(&m->src_ports, &src_ports);
+ sset_swap(&m->dst_ports, &dst_ports);
free(m->vlans);
m->vlans = vlans;
m->n_vlans = n_vlans;
/* Update ports. */
mirror_bit = MIRROR_MASK_C(1) << m->idx;
HMAP_FOR_EACH (port, hmap_node, &m->bridge->ports) {
- if (shash_find(&m->src_ports, port->name)
+ if (sset_contains(&m->src_ports, port->name)
|| (m->n_vlans
&& (!port->vlan
? port_trunks_any_mirrored_vlan(m, port)
port->src_mirrors &= ~mirror_bit;
}
- if (shash_find(&m->dst_ports, port->name)) {
+ if (sset_contains(&m->dst_ports, port->name)) {
port->dst_mirrors |= mirror_bit;
} else {
port->dst_mirrors &= ~mirror_bit;
}
/* Clean up. */
- shash_destroy(&src_ports);
- shash_destroy(&dst_ports);
+ sset_destroy(&src_ports);
+ sset_destroy(&dst_ports);
}