mirror of
https://github.com/openvswitch/ovs
synced 2025-09-02 23:35:27 +00:00
Convert shash users that don't use the 'data' value to sset instead.
In each of the cases converted here, an shash was used simply to maintain a set of strings, with the shash_nodes' 'data' values set to NULL. This commit converts them to use sset instead.
This commit is contained in:
@@ -45,6 +45,7 @@
|
|||||||
#include "rtnetlink.h"
|
#include "rtnetlink.h"
|
||||||
#include "rtnetlink-link.h"
|
#include "rtnetlink-link.h"
|
||||||
#include "shash.h"
|
#include "shash.h"
|
||||||
|
#include "sset.h"
|
||||||
#include "svec.h"
|
#include "svec.h"
|
||||||
#include "unaligned.h"
|
#include "unaligned.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
@@ -125,7 +126,7 @@ struct dpif_linux {
|
|||||||
unsigned int listen_mask;
|
unsigned int listen_mask;
|
||||||
|
|
||||||
/* Change notification. */
|
/* Change notification. */
|
||||||
struct shash changed_ports; /* Ports that have changed. */
|
struct sset changed_ports; /* Ports that have changed. */
|
||||||
struct rtnetlink_notifier port_notifier;
|
struct rtnetlink_notifier port_notifier;
|
||||||
bool change_error;
|
bool change_error;
|
||||||
};
|
};
|
||||||
@@ -231,7 +232,7 @@ open_dpif(const struct dpif_linux_dp *dp, struct dpif **dpifp)
|
|||||||
}
|
}
|
||||||
dpif->listen_mask = 0;
|
dpif->listen_mask = 0;
|
||||||
dpif->dp_ifindex = dp->dp_ifindex;
|
dpif->dp_ifindex = dp->dp_ifindex;
|
||||||
shash_init(&dpif->changed_ports);
|
sset_init(&dpif->changed_ports);
|
||||||
dpif->change_error = false;
|
dpif->change_error = false;
|
||||||
*dpifp = &dpif->dpif;
|
*dpifp = &dpif->dpif;
|
||||||
|
|
||||||
@@ -247,7 +248,7 @@ dpif_linux_close(struct dpif *dpif_)
|
|||||||
{
|
{
|
||||||
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
|
struct dpif_linux *dpif = dpif_linux_cast(dpif_);
|
||||||
rtnetlink_link_notifier_unregister(&dpif->port_notifier);
|
rtnetlink_link_notifier_unregister(&dpif->port_notifier);
|
||||||
shash_destroy(&dpif->changed_ports);
|
sset_destroy(&dpif->changed_ports);
|
||||||
free(dpif);
|
free(dpif);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -483,11 +484,10 @@ dpif_linux_port_poll(const struct dpif *dpif_, char **devnamep)
|
|||||||
|
|
||||||
if (dpif->change_error) {
|
if (dpif->change_error) {
|
||||||
dpif->change_error = false;
|
dpif->change_error = false;
|
||||||
shash_clear(&dpif->changed_ports);
|
sset_clear(&dpif->changed_ports);
|
||||||
return ENOBUFS;
|
return ENOBUFS;
|
||||||
} else if (!shash_is_empty(&dpif->changed_ports)) {
|
} else if (!sset_is_empty(&dpif->changed_ports)) {
|
||||||
struct shash_node *node = shash_first(&dpif->changed_ports);
|
*devnamep = sset_pop(&dpif->changed_ports);
|
||||||
*devnamep = shash_steal(&dpif->changed_ports, node);
|
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
return EAGAIN;
|
return EAGAIN;
|
||||||
@@ -498,7 +498,7 @@ static void
|
|||||||
dpif_linux_port_poll_wait(const struct dpif *dpif_)
|
dpif_linux_port_poll_wait(const struct dpif *dpif_)
|
||||||
{
|
{
|
||||||
struct dpif_linux *dpif = dpif_linux_cast(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();
|
poll_immediate_wake();
|
||||||
} else {
|
} else {
|
||||||
rtnetlink_link_notifier_wait();
|
rtnetlink_link_notifier_wait();
|
||||||
@@ -1041,7 +1041,7 @@ dpif_linux_port_changed(const struct rtnetlink_link_change *change,
|
|||||||
{
|
{
|
||||||
/* Our datapath changed, either adding a new port or deleting an
|
/* Our datapath changed, either adding a new port or deleting an
|
||||||
* existing one. */
|
* existing one. */
|
||||||
shash_add_once(&dpif->changed_ports, change->ifname, NULL);
|
sset_add(&dpif->changed_ports, change->ifname);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
dpif->change_error = true;
|
dpif->change_error = true;
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* 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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -26,6 +26,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "poll-loop.h"
|
#include "poll-loop.h"
|
||||||
#include "shash.h"
|
#include "shash.h"
|
||||||
|
#include "sset.h"
|
||||||
#include "socket-util.h"
|
#include "socket-util.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "vlog.h"
|
#include "vlog.h"
|
||||||
@@ -194,8 +195,8 @@ call_hooks(int sig_nr)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Files to delete on exit. (The 'data' member of each node is unused.) */
|
/* Files to delete on exit. */
|
||||||
static struct shash files = SHASH_INITIALIZER(&files);
|
static struct sset files = SSET_INITIALIZER(&files);
|
||||||
|
|
||||||
/* Has a hook function been registered with fatal_signal_add_hook() (and not
|
/* Has a hook function been registered with fatal_signal_add_hook() (and not
|
||||||
* cleared by fatal_signal_fork())? */
|
* cleared by fatal_signal_fork())? */
|
||||||
@@ -215,7 +216,7 @@ fatal_signal_add_file_to_unlink(const char *file)
|
|||||||
fatal_signal_add_hook(unlink_files, cancel_files, NULL, true);
|
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
|
/* Unregisters 'file' from being unlinked when the program terminates via
|
||||||
@@ -223,12 +224,7 @@ fatal_signal_add_file_to_unlink(const char *file)
|
|||||||
void
|
void
|
||||||
fatal_signal_remove_file_to_unlink(const char *file)
|
fatal_signal_remove_file_to_unlink(const char *file)
|
||||||
{
|
{
|
||||||
struct shash_node *node;
|
sset_find_and_delete(&files, file);
|
||||||
|
|
||||||
node = shash_find(&files, file);
|
|
||||||
if (node) {
|
|
||||||
shash_delete(&files, node);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Like fatal_signal_remove_file_to_unlink(), but also unlinks 'file'.
|
/* Like fatal_signal_remove_file_to_unlink(), but also unlinks 'file'.
|
||||||
@@ -255,17 +251,17 @@ unlink_files(void *aux OVS_UNUSED)
|
|||||||
static void
|
static void
|
||||||
cancel_files(void *aux OVS_UNUSED)
|
cancel_files(void *aux OVS_UNUSED)
|
||||||
{
|
{
|
||||||
shash_clear(&files);
|
sset_clear(&files);
|
||||||
added_hook = false;
|
added_hook = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
do_unlink_files(void)
|
do_unlink_files(void)
|
||||||
{
|
{
|
||||||
struct shash_node *node;
|
const char *file;
|
||||||
|
|
||||||
SHASH_FOR_EACH (node, &files) {
|
SSET_FOR_EACH (file, &files) {
|
||||||
unlink(node->name);
|
unlink(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
21
lib/netdev.c
21
lib/netdev.c
@@ -37,6 +37,7 @@
|
|||||||
#include "packets.h"
|
#include "packets.h"
|
||||||
#include "poll-loop.h"
|
#include "poll-loop.h"
|
||||||
#include "shash.h"
|
#include "shash.h"
|
||||||
|
#include "sset.h"
|
||||||
#include "svec.h"
|
#include "svec.h"
|
||||||
#include "vlog.h"
|
#include "vlog.h"
|
||||||
|
|
||||||
@@ -1444,7 +1445,7 @@ netdev_notifier_init(struct netdev_notifier *notifier, struct netdev *netdev,
|
|||||||
/* Tracks changes in the status of a set of network devices. */
|
/* Tracks changes in the status of a set of network devices. */
|
||||||
struct netdev_monitor {
|
struct netdev_monitor {
|
||||||
struct shash polled_netdevs;
|
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
|
/* Creates and returns a new structure for monitor changes in the status of
|
||||||
@@ -1454,7 +1455,7 @@ netdev_monitor_create(void)
|
|||||||
{
|
{
|
||||||
struct netdev_monitor *monitor = xmalloc(sizeof *monitor);
|
struct netdev_monitor *monitor = xmalloc(sizeof *monitor);
|
||||||
shash_init(&monitor->polled_netdevs);
|
shash_init(&monitor->polled_netdevs);
|
||||||
shash_init(&monitor->changed_netdevs);
|
sset_init(&monitor->changed_netdevs);
|
||||||
return monitor;
|
return monitor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1472,7 +1473,7 @@ netdev_monitor_destroy(struct netdev_monitor *monitor)
|
|||||||
}
|
}
|
||||||
|
|
||||||
shash_destroy(&monitor->polled_netdevs);
|
shash_destroy(&monitor->polled_netdevs);
|
||||||
shash_destroy(&monitor->changed_netdevs);
|
sset_destroy(&monitor->changed_netdevs);
|
||||||
free(monitor);
|
free(monitor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1482,7 +1483,7 @@ netdev_monitor_cb(struct netdev_notifier *notifier)
|
|||||||
{
|
{
|
||||||
struct netdev_monitor *monitor = notifier->aux;
|
struct netdev_monitor *monitor = notifier->aux;
|
||||||
const char *name = netdev_get_name(notifier->netdev);
|
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
|
/* Attempts to add 'netdev' as a netdev monitored by 'monitor'. Returns 0 if
|
||||||
@@ -1526,10 +1527,7 @@ netdev_monitor_remove(struct netdev_monitor *monitor, struct netdev *netdev)
|
|||||||
shash_delete(&monitor->polled_netdevs, node);
|
shash_delete(&monitor->polled_netdevs, node);
|
||||||
|
|
||||||
/* Drop any pending notification. */
|
/* Drop any pending notification. */
|
||||||
node = shash_find(&monitor->changed_netdevs, netdev_name);
|
sset_find_and_delete(&monitor->changed_netdevs, netdev_name);
|
||||||
if (node) {
|
|
||||||
shash_delete(&monitor->changed_netdevs, node);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1543,12 +1541,11 @@ netdev_monitor_remove(struct netdev_monitor *monitor, struct netdev *netdev)
|
|||||||
int
|
int
|
||||||
netdev_monitor_poll(struct netdev_monitor *monitor, char **devnamep)
|
netdev_monitor_poll(struct netdev_monitor *monitor, char **devnamep)
|
||||||
{
|
{
|
||||||
struct shash_node *node = shash_first(&monitor->changed_netdevs);
|
if (sset_is_empty(&monitor->changed_netdevs)) {
|
||||||
if (!node) {
|
|
||||||
*devnamep = NULL;
|
*devnamep = NULL;
|
||||||
return EAGAIN;
|
return EAGAIN;
|
||||||
} else {
|
} else {
|
||||||
*devnamep = shash_steal(&monitor->changed_netdevs, node);
|
*devnamep = sset_pop(&monitor->changed_netdevs);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1559,7 +1556,7 @@ netdev_monitor_poll(struct netdev_monitor *monitor, char **devnamep)
|
|||||||
void
|
void
|
||||||
netdev_monitor_poll_wait(const struct netdev_monitor *monitor)
|
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();
|
poll_immediate_wake();
|
||||||
} else {
|
} else {
|
||||||
/* XXX Nothing needed here for netdev_linux, but maybe other netdev
|
/* XXX Nothing needed here for netdev_linux, but maybe other netdev
|
||||||
|
@@ -55,6 +55,7 @@
|
|||||||
#include "poll-loop.h"
|
#include "poll-loop.h"
|
||||||
#include "rconn.h"
|
#include "rconn.h"
|
||||||
#include "shash.h"
|
#include "shash.h"
|
||||||
|
#include "sset.h"
|
||||||
#include "stream-ssl.h"
|
#include "stream-ssl.h"
|
||||||
#include "svec.h"
|
#include "svec.h"
|
||||||
#include "tag.h"
|
#include "tag.h"
|
||||||
@@ -1026,25 +1027,25 @@ static void
|
|||||||
reinit_ports(struct ofproto *p)
|
reinit_ports(struct ofproto *p)
|
||||||
{
|
{
|
||||||
struct dpif_port_dump dump;
|
struct dpif_port_dump dump;
|
||||||
struct shash_node *node;
|
struct sset devnames;
|
||||||
struct shash devnames;
|
|
||||||
struct ofport *ofport;
|
struct ofport *ofport;
|
||||||
struct dpif_port dpif_port;
|
struct dpif_port dpif_port;
|
||||||
|
const char *devname;
|
||||||
|
|
||||||
COVERAGE_INC(ofproto_reinit_ports);
|
COVERAGE_INC(ofproto_reinit_ports);
|
||||||
|
|
||||||
shash_init(&devnames);
|
sset_init(&devnames);
|
||||||
HMAP_FOR_EACH (ofport, hmap_node, &p->ports) {
|
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) {
|
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) {
|
SSET_FOR_EACH (devname, &devnames) {
|
||||||
update_port(p, node->name);
|
update_port(p, devname);
|
||||||
}
|
}
|
||||||
shash_destroy(&devnames);
|
sset_destroy(&devnames);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct ofport *
|
static struct ofport *
|
||||||
|
@@ -40,7 +40,7 @@
|
|||||||
#include "stream-ssl.h"
|
#include "stream-ssl.h"
|
||||||
#include "stream.h"
|
#include "stream.h"
|
||||||
#include "stress.h"
|
#include "stress.h"
|
||||||
#include "svec.h"
|
#include "sset.h"
|
||||||
#include "table.h"
|
#include "table.h"
|
||||||
#include "timeval.h"
|
#include "timeval.h"
|
||||||
#include "transaction.h"
|
#include "transaction.h"
|
||||||
@@ -64,15 +64,15 @@ static unixctl_cb_func ovsdb_server_compact;
|
|||||||
static unixctl_cb_func ovsdb_server_reconnect;
|
static unixctl_cb_func ovsdb_server_reconnect;
|
||||||
|
|
||||||
static void parse_options(int argc, char *argv[], char **file_namep,
|
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);
|
char **run_command);
|
||||||
static void usage(void) NO_RETURN;
|
static void usage(void) NO_RETURN;
|
||||||
|
|
||||||
static void reconfigure_from_db(struct ovsdb_jsonrpc_server *jsonrpc,
|
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,
|
static void update_remote_status(const struct ovsdb_jsonrpc_server *jsonrpc,
|
||||||
const struct shash *remotes,
|
const struct sset *remotes,
|
||||||
struct ovsdb *db);
|
struct ovsdb *db);
|
||||||
|
|
||||||
int
|
int
|
||||||
@@ -82,7 +82,7 @@ main(int argc, char *argv[])
|
|||||||
char *run_command = NULL;
|
char *run_command = NULL;
|
||||||
struct unixctl_server *unixctl;
|
struct unixctl_server *unixctl;
|
||||||
struct ovsdb_jsonrpc_server *jsonrpc;
|
struct ovsdb_jsonrpc_server *jsonrpc;
|
||||||
struct shash remotes;
|
struct sset remotes;
|
||||||
struct ovsdb_error *error;
|
struct ovsdb_error *error;
|
||||||
struct ovsdb_file *file;
|
struct ovsdb_file *file;
|
||||||
struct ovsdb *db;
|
struct ovsdb *db;
|
||||||
@@ -171,7 +171,7 @@ main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
ovsdb_jsonrpc_server_destroy(jsonrpc);
|
ovsdb_jsonrpc_server_destroy(jsonrpc);
|
||||||
ovsdb_destroy(db);
|
ovsdb_destroy(db);
|
||||||
shash_destroy_free_data(&remotes);
|
sset_destroy(&remotes);
|
||||||
unixctl_server_destroy(unixctl);
|
unixctl_server_destroy(unixctl);
|
||||||
|
|
||||||
if (run_process && process_exited(run_process)) {
|
if (run_process && process_exited(run_process)) {
|
||||||
@@ -551,14 +551,14 @@ update_remote_rows(const struct ovsdb *db, struct ovsdb_txn *txn,
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
update_remote_status(const struct ovsdb_jsonrpc_server *jsonrpc,
|
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);
|
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
|
||||||
struct shash_node *remote;
|
|
||||||
struct shash statuses;
|
struct shash statuses;
|
||||||
struct ovsdb_txn *txn;
|
struct ovsdb_txn *txn;
|
||||||
const bool durable_txn = false;
|
const bool durable_txn = false;
|
||||||
struct ovsdb_error *error;
|
struct ovsdb_error *error;
|
||||||
|
const char *remote;
|
||||||
|
|
||||||
/* Get status of current connections. */
|
/* Get status of current connections. */
|
||||||
ovsdb_jsonrpc_server_get_remote_status(jsonrpc, &statuses);
|
ovsdb_jsonrpc_server_get_remote_status(jsonrpc, &statuses);
|
||||||
@@ -566,8 +566,8 @@ update_remote_status(const struct ovsdb_jsonrpc_server *jsonrpc,
|
|||||||
txn = ovsdb_txn_create(db);
|
txn = ovsdb_txn_create(db);
|
||||||
|
|
||||||
/* Iterate over --remote arguments given on command line. */
|
/* Iterate over --remote arguments given on command line. */
|
||||||
SHASH_FOR_EACH (remote, remotes) {
|
SSET_FOR_EACH (remote, remotes) {
|
||||||
update_remote_rows(db, txn, remote->name, &statuses);
|
update_remote_rows(db, txn, remote, &statuses);
|
||||||
}
|
}
|
||||||
|
|
||||||
error = ovsdb_txn_commit(txn, durable_txn);
|
error = ovsdb_txn_commit(txn, durable_txn);
|
||||||
@@ -582,16 +582,14 @@ update_remote_status(const struct ovsdb_jsonrpc_server *jsonrpc,
|
|||||||
/* Reconfigures ovsdb-server based on information in the database. */
|
/* Reconfigures ovsdb-server based on information in the database. */
|
||||||
static void
|
static void
|
||||||
reconfigure_from_db(struct ovsdb_jsonrpc_server *jsonrpc,
|
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 resolved_remotes;
|
||||||
struct shash_node *node;
|
const char *name;
|
||||||
|
|
||||||
/* Configure remotes. */
|
/* Configure remotes. */
|
||||||
shash_init(&resolved_remotes);
|
shash_init(&resolved_remotes);
|
||||||
SHASH_FOR_EACH (node, remotes) {
|
SSET_FOR_EACH (name, remotes) {
|
||||||
const char *name = node->name;
|
|
||||||
|
|
||||||
if (!strncmp(name, "db:", 3)) {
|
if (!strncmp(name, "db:", 3)) {
|
||||||
query_db_remotes(name, db, &resolved_remotes);
|
query_db_remotes(name, db, &resolved_remotes);
|
||||||
} else {
|
} else {
|
||||||
@@ -652,7 +650,7 @@ ovsdb_server_reconnect(struct unixctl_conn *conn, const char *args OVS_UNUSED,
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
parse_options(int argc, char *argv[], char **file_namep,
|
parse_options(int argc, char *argv[], char **file_namep,
|
||||||
struct shash *remotes, char **unixctl_pathp,
|
struct sset *remotes, char **unixctl_pathp,
|
||||||
char **run_command)
|
char **run_command)
|
||||||
{
|
{
|
||||||
enum {
|
enum {
|
||||||
@@ -684,7 +682,7 @@ parse_options(int argc, char *argv[], char **file_namep,
|
|||||||
};
|
};
|
||||||
char *short_options = long_options_to_short_options(long_options);
|
char *short_options = long_options_to_short_options(long_options);
|
||||||
|
|
||||||
shash_init(remotes);
|
sset_init(remotes);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
@@ -695,7 +693,7 @@ parse_options(int argc, char *argv[], char **file_namep,
|
|||||||
|
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case OPT_REMOTE:
|
case OPT_REMOTE:
|
||||||
shash_add_once(remotes, optarg, NULL);
|
sset_add(remotes, optarg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OPT_UNIXCTL:
|
case OPT_UNIXCTL:
|
||||||
|
@@ -38,6 +38,7 @@
|
|||||||
#include "process.h"
|
#include "process.h"
|
||||||
#include "stream.h"
|
#include "stream.h"
|
||||||
#include "stream-ssl.h"
|
#include "stream-ssl.h"
|
||||||
|
#include "sset.h"
|
||||||
#include "svec.h"
|
#include "svec.h"
|
||||||
#include "vswitchd/vswitch-idl.h"
|
#include "vswitchd/vswitch-idl.h"
|
||||||
#include "table.h"
|
#include "table.h"
|
||||||
@@ -757,7 +758,7 @@ static void
|
|||||||
get_info(struct vsctl_context *ctx, struct vsctl_info *info)
|
get_info(struct vsctl_context *ctx, struct vsctl_info *info)
|
||||||
{
|
{
|
||||||
const struct ovsrec_open_vswitch *ovs = ctx->ovs;
|
const struct ovsrec_open_vswitch *ovs = ctx->ovs;
|
||||||
struct shash bridges, ports;
|
struct sset bridges, ports;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
info->ctx = ctx;
|
info->ctx = ctx;
|
||||||
@@ -765,14 +766,14 @@ get_info(struct vsctl_context *ctx, struct vsctl_info *info)
|
|||||||
shash_init(&info->ports);
|
shash_init(&info->ports);
|
||||||
shash_init(&info->ifaces);
|
shash_init(&info->ifaces);
|
||||||
|
|
||||||
shash_init(&bridges);
|
sset_init(&bridges);
|
||||||
shash_init(&ports);
|
sset_init(&ports);
|
||||||
for (i = 0; i < ovs->n_bridges; i++) {
|
for (i = 0; i < ovs->n_bridges; i++) {
|
||||||
struct ovsrec_bridge *br_cfg = ovs->bridges[i];
|
struct ovsrec_bridge *br_cfg = ovs->bridges[i];
|
||||||
struct vsctl_bridge *br;
|
struct vsctl_bridge *br;
|
||||||
size_t j;
|
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",
|
VLOG_WARN("%s: database contains duplicate bridge name",
|
||||||
br_cfg->name);
|
br_cfg->name);
|
||||||
continue;
|
continue;
|
||||||
@@ -785,29 +786,29 @@ get_info(struct vsctl_context *ctx, struct vsctl_info *info)
|
|||||||
for (j = 0; j < br_cfg->n_ports; j++) {
|
for (j = 0; j < br_cfg->n_ports; j++) {
|
||||||
struct ovsrec_port *port_cfg = br_cfg->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",
|
VLOG_WARN("%s: database contains duplicate port name",
|
||||||
port_cfg->name);
|
port_cfg->name);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (port_is_fake_bridge(port_cfg)
|
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);
|
add_bridge(info, NULL, port_cfg->name, br, *port_cfg->tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
shash_destroy(&bridges);
|
sset_destroy(&bridges);
|
||||||
shash_destroy(&ports);
|
sset_destroy(&ports);
|
||||||
|
|
||||||
shash_init(&bridges);
|
sset_init(&bridges);
|
||||||
shash_init(&ports);
|
sset_init(&ports);
|
||||||
for (i = 0; i < ovs->n_bridges; i++) {
|
for (i = 0; i < ovs->n_bridges; i++) {
|
||||||
struct ovsrec_bridge *br_cfg = ovs->bridges[i];
|
struct ovsrec_bridge *br_cfg = ovs->bridges[i];
|
||||||
struct vsctl_bridge *br;
|
struct vsctl_bridge *br;
|
||||||
size_t j;
|
size_t j;
|
||||||
|
|
||||||
if (!shash_add_once(&bridges, br_cfg->name, NULL)) {
|
if (!sset_add(&bridges, br_cfg->name)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
br = shash_find_data(&info->bridges, br_cfg->name);
|
br = shash_find_data(&info->bridges, br_cfg->name);
|
||||||
@@ -816,12 +817,12 @@ get_info(struct vsctl_context *ctx, struct vsctl_info *info)
|
|||||||
struct vsctl_port *port;
|
struct vsctl_port *port;
|
||||||
size_t k;
|
size_t k;
|
||||||
|
|
||||||
if (!shash_add_once(&ports, port_cfg->name, NULL)) {
|
if (!sset_add(&ports, port_cfg->name)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (port_is_fake_bridge(port_cfg)
|
if (port_is_fake_bridge(port_cfg)
|
||||||
&& !shash_add_once(&bridges, port_cfg->name, NULL)) {
|
&& !sset_add(&bridges, port_cfg->name)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -855,8 +856,8 @@ get_info(struct vsctl_context *ctx, struct vsctl_info *info)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
shash_destroy(&bridges);
|
sset_destroy(&bridges);
|
||||||
shash_destroy(&ports);
|
sset_destroy(&ports);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@@ -61,6 +61,7 @@
|
|||||||
#include "shash.h"
|
#include "shash.h"
|
||||||
#include "socket-util.h"
|
#include "socket-util.h"
|
||||||
#include "stream-ssl.h"
|
#include "stream-ssl.h"
|
||||||
|
#include "sset.h"
|
||||||
#include "svec.h"
|
#include "svec.h"
|
||||||
#include "system-stats.h"
|
#include "system-stats.h"
|
||||||
#include "timeval.h"
|
#include "timeval.h"
|
||||||
@@ -142,8 +143,8 @@ struct mirror {
|
|||||||
struct uuid uuid; /* UUID of this "mirror" record in database. */
|
struct uuid uuid; /* UUID of this "mirror" record in database. */
|
||||||
|
|
||||||
/* Selection criteria. */
|
/* Selection criteria. */
|
||||||
struct shash src_ports; /* Name is port name; data is always NULL. */
|
struct sset src_ports; /* Source port names. */
|
||||||
struct shash dst_ports; /* Name is port name; data is always NULL. */
|
struct sset dst_ports; /* Destination port names. */
|
||||||
int *vlans;
|
int *vlans;
|
||||||
size_t n_vlans;
|
size_t n_vlans;
|
||||||
|
|
||||||
@@ -506,30 +507,29 @@ collect_in_band_managers(const struct ovsrec_open_vswitch *ovs_cfg,
|
|||||||
{
|
{
|
||||||
struct sockaddr_in *managers = NULL;
|
struct sockaddr_in *managers = NULL;
|
||||||
size_t n_managers = 0;
|
size_t n_managers = 0;
|
||||||
struct shash targets;
|
struct sset targets;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
/* Collect all of the potential targets from the "targets" columns of the
|
/* Collect all of the potential targets from the "targets" columns of the
|
||||||
* rows pointed to by "manager_options", excluding any that are
|
* rows pointed to by "manager_options", excluding any that are
|
||||||
* out-of-band. */
|
* out-of-band. */
|
||||||
shash_init(&targets);
|
sset_init(&targets);
|
||||||
for (i = 0; i < ovs_cfg->n_manager_options; i++) {
|
for (i = 0; i < ovs_cfg->n_manager_options; i++) {
|
||||||
struct ovsrec_manager *m = ovs_cfg->manager_options[i];
|
struct ovsrec_manager *m = ovs_cfg->manager_options[i];
|
||||||
|
|
||||||
if (m->connection_mode && !strcmp(m->connection_mode, "out-of-band")) {
|
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 {
|
} else {
|
||||||
shash_add_once(&targets, m->target, NULL);
|
sset_add(&targets, m->target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now extract the targets' IP addresses. */
|
/* Now extract the targets' IP addresses. */
|
||||||
if (!shash_is_empty(&targets)) {
|
if (!sset_is_empty(&targets)) {
|
||||||
struct shash_node *node;
|
const char *target;
|
||||||
|
|
||||||
managers = xmalloc(shash_count(&targets) * sizeof *managers);
|
managers = xmalloc(sset_count(&targets) * sizeof *managers);
|
||||||
SHASH_FOR_EACH (node, &targets) {
|
SSET_FOR_EACH (target, &targets) {
|
||||||
const char *target = node->name;
|
|
||||||
struct sockaddr_in *sin = &managers[n_managers];
|
struct sockaddr_in *sin = &managers[n_managers];
|
||||||
|
|
||||||
if ((!strncmp(target, "tcp:", 4)
|
if ((!strncmp(target, "tcp:", 4)
|
||||||
@@ -540,7 +540,7 @@ collect_in_band_managers(const struct ovsrec_open_vswitch *ovs_cfg,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
shash_destroy(&targets);
|
sset_destroy(&targets);
|
||||||
|
|
||||||
*managersp = managers;
|
*managersp = managers;
|
||||||
*n_managersp = n_managers;
|
*n_managersp = n_managers;
|
||||||
@@ -3947,24 +3947,24 @@ static void
|
|||||||
port_del_ifaces(struct port *port, const struct ovsrec_port *cfg)
|
port_del_ifaces(struct port *port, const struct ovsrec_port *cfg)
|
||||||
{
|
{
|
||||||
struct iface *iface, *next;
|
struct iface *iface, *next;
|
||||||
struct shash new_ifaces;
|
struct sset new_ifaces;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
/* Collect list of new interfaces. */
|
/* Collect list of new interfaces. */
|
||||||
shash_init(&new_ifaces);
|
sset_init(&new_ifaces);
|
||||||
for (i = 0; i < cfg->n_interfaces; i++) {
|
for (i = 0; i < cfg->n_interfaces; i++) {
|
||||||
const char *name = cfg->interfaces[i]->name;
|
const char *name = cfg->interfaces[i]->name;
|
||||||
shash_add_once(&new_ifaces, name, NULL);
|
sset_add(&new_ifaces, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get rid of deleted interfaces. */
|
/* Get rid of deleted interfaces. */
|
||||||
LIST_FOR_EACH_SAFE (iface, next, port_elem, &port->ifaces) {
|
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);
|
iface_destroy(iface);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
shash_destroy(&new_ifaces);
|
sset_destroy(&new_ifaces);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Expires all MAC learning entries associated with 'port' and forces ofproto
|
/* Expires all MAC learning entries associated with 'port' and forces ofproto
|
||||||
@@ -3988,7 +3988,7 @@ static void
|
|||||||
port_reconfigure(struct port *port, const struct ovsrec_port *cfg)
|
port_reconfigure(struct port *port, const struct ovsrec_port *cfg)
|
||||||
{
|
{
|
||||||
const char *detect_mode;
|
const char *detect_mode;
|
||||||
struct shash new_ifaces;
|
struct sset new_ifaces;
|
||||||
long long int next_rebalance, miimon_next_update, lacp_priority;
|
long long int next_rebalance, miimon_next_update, lacp_priority;
|
||||||
bool need_flush = false;
|
bool need_flush = false;
|
||||||
unsigned long *trunks;
|
unsigned long *trunks;
|
||||||
@@ -4056,12 +4056,12 @@ port_reconfigure(struct port *port, const struct ovsrec_port *cfg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Add new interfaces and update 'cfg' member of existing ones. */
|
/* 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++) {
|
for (i = 0; i < cfg->n_interfaces; i++) {
|
||||||
const struct ovsrec_interface *if_cfg = cfg->interfaces[i];
|
const struct ovsrec_interface *if_cfg = cfg->interfaces[i];
|
||||||
struct iface *iface;
|
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",
|
VLOG_WARN("port %s: %s specified twice as port interface",
|
||||||
port->name, if_cfg->name);
|
port->name, if_cfg->name);
|
||||||
iface_set_ofport(if_cfg, -1);
|
iface_set_ofport(if_cfg, -1);
|
||||||
@@ -4098,7 +4098,7 @@ port_reconfigure(struct port *port, const struct ovsrec_port *cfg)
|
|||||||
iface->lacp_priority = lacp_priority;
|
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"),
|
port->lacp_fast = !strcmp(get_port_other_config(cfg, "lacp-time", "slow"),
|
||||||
"fast");
|
"fast");
|
||||||
@@ -4753,8 +4753,8 @@ mirror_create(struct bridge *br, struct ovsrec_mirror *cfg)
|
|||||||
m->bridge = br;
|
m->bridge = br;
|
||||||
m->idx = i;
|
m->idx = i;
|
||||||
m->name = xstrdup(cfg->name);
|
m->name = xstrdup(cfg->name);
|
||||||
shash_init(&m->src_ports);
|
sset_init(&m->src_ports);
|
||||||
shash_init(&m->dst_ports);
|
sset_init(&m->dst_ports);
|
||||||
m->vlans = NULL;
|
m->vlans = NULL;
|
||||||
m->n_vlans = 0;
|
m->n_vlans = 0;
|
||||||
m->out_vlan = -1;
|
m->out_vlan = -1;
|
||||||
@@ -4775,8 +4775,8 @@ mirror_destroy(struct mirror *m)
|
|||||||
port->dst_mirrors &= ~(MIRROR_MASK_C(1) << m->idx);
|
port->dst_mirrors &= ~(MIRROR_MASK_C(1) << m->idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
shash_destroy(&m->src_ports);
|
sset_destroy(&m->src_ports);
|
||||||
shash_destroy(&m->dst_ports);
|
sset_destroy(&m->dst_ports);
|
||||||
free(m->vlans);
|
free(m->vlans);
|
||||||
|
|
||||||
m->bridge->mirrors[m->idx] = NULL;
|
m->bridge->mirrors[m->idx] = NULL;
|
||||||
@@ -4790,14 +4790,14 @@ mirror_destroy(struct mirror *m)
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
mirror_collect_ports(struct mirror *m, struct ovsrec_port **ports, int n_ports,
|
mirror_collect_ports(struct mirror *m, struct ovsrec_port **ports, int n_ports,
|
||||||
struct shash *names)
|
struct sset *names)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
for (i = 0; i < n_ports; i++) {
|
for (i = 0; i < n_ports; i++) {
|
||||||
const char *name = ports[i]->name;
|
const char *name = ports[i]->name;
|
||||||
if (port_lookup(m->bridge, name)) {
|
if (port_lookup(m->bridge, name)) {
|
||||||
shash_add_once(names, name, NULL);
|
sset_add(names, name);
|
||||||
} else {
|
} else {
|
||||||
VLOG_WARN("bridge %s: mirror %s cannot match on nonexistent "
|
VLOG_WARN("bridge %s: mirror %s cannot match on nonexistent "
|
||||||
"port %s", m->bridge->name, m->name, name);
|
"port %s", m->bridge->name, m->name, name);
|
||||||
@@ -4855,7 +4855,7 @@ port_trunks_any_mirrored_vlan(const struct mirror *m, const struct port *p)
|
|||||||
static void
|
static void
|
||||||
mirror_reconfigure_one(struct mirror *m, struct ovsrec_mirror *cfg)
|
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;
|
mirror_mask_t mirror_bit;
|
||||||
struct port *out_port;
|
struct port *out_port;
|
||||||
struct port *port;
|
struct port *port;
|
||||||
@@ -4895,12 +4895,12 @@ mirror_reconfigure_one(struct mirror *m, struct ovsrec_mirror *cfg)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
shash_init(&src_ports);
|
sset_init(&src_ports);
|
||||||
shash_init(&dst_ports);
|
sset_init(&dst_ports);
|
||||||
if (cfg->select_all) {
|
if (cfg->select_all) {
|
||||||
HMAP_FOR_EACH (port, hmap_node, &m->bridge->ports) {
|
HMAP_FOR_EACH (port, hmap_node, &m->bridge->ports) {
|
||||||
shash_add_once(&src_ports, port->name, NULL);
|
sset_add(&src_ports, port->name);
|
||||||
shash_add_once(&dst_ports, port->name, NULL);
|
sset_add(&dst_ports, port->name);
|
||||||
}
|
}
|
||||||
vlans = NULL;
|
vlans = NULL;
|
||||||
n_vlans = 0;
|
n_vlans = 0;
|
||||||
@@ -4916,8 +4916,8 @@ mirror_reconfigure_one(struct mirror *m, struct ovsrec_mirror *cfg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Update mirror data. */
|
/* Update mirror data. */
|
||||||
if (!shash_equal_keys(&m->src_ports, &src_ports)
|
if (!sset_equals(&m->src_ports, &src_ports)
|
||||||
|| !shash_equal_keys(&m->dst_ports, &dst_ports)
|
|| !sset_equals(&m->dst_ports, &dst_ports)
|
||||||
|| m->n_vlans != n_vlans
|
|| m->n_vlans != n_vlans
|
||||||
|| memcmp(m->vlans, vlans, sizeof *vlans * n_vlans)
|
|| memcmp(m->vlans, vlans, sizeof *vlans * n_vlans)
|
||||||
|| m->out_port != out_port
|
|| m->out_port != out_port
|
||||||
@@ -4925,8 +4925,8 @@ mirror_reconfigure_one(struct mirror *m, struct ovsrec_mirror *cfg)
|
|||||||
bridge_flush(m->bridge);
|
bridge_flush(m->bridge);
|
||||||
mac_learning_flush(m->bridge->ml);
|
mac_learning_flush(m->bridge->ml);
|
||||||
}
|
}
|
||||||
shash_swap(&m->src_ports, &src_ports);
|
sset_swap(&m->src_ports, &src_ports);
|
||||||
shash_swap(&m->dst_ports, &dst_ports);
|
sset_swap(&m->dst_ports, &dst_ports);
|
||||||
free(m->vlans);
|
free(m->vlans);
|
||||||
m->vlans = vlans;
|
m->vlans = vlans;
|
||||||
m->n_vlans = n_vlans;
|
m->n_vlans = n_vlans;
|
||||||
@@ -4936,7 +4936,7 @@ mirror_reconfigure_one(struct mirror *m, struct ovsrec_mirror *cfg)
|
|||||||
/* Update ports. */
|
/* Update ports. */
|
||||||
mirror_bit = MIRROR_MASK_C(1) << m->idx;
|
mirror_bit = MIRROR_MASK_C(1) << m->idx;
|
||||||
HMAP_FOR_EACH (port, hmap_node, &m->bridge->ports) {
|
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
|
|| (m->n_vlans
|
||||||
&& (!port->vlan
|
&& (!port->vlan
|
||||||
? port_trunks_any_mirrored_vlan(m, port)
|
? port_trunks_any_mirrored_vlan(m, port)
|
||||||
@@ -4946,7 +4946,7 @@ mirror_reconfigure_one(struct mirror *m, struct ovsrec_mirror *cfg)
|
|||||||
port->src_mirrors &= ~mirror_bit;
|
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;
|
port->dst_mirrors |= mirror_bit;
|
||||||
} else {
|
} else {
|
||||||
port->dst_mirrors &= ~mirror_bit;
|
port->dst_mirrors &= ~mirror_bit;
|
||||||
@@ -4954,6 +4954,6 @@ mirror_reconfigure_one(struct mirror *m, struct ovsrec_mirror *cfg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Clean up. */
|
/* Clean up. */
|
||||||
shash_destroy(&src_ports);
|
sset_destroy(&src_ports);
|
||||||
shash_destroy(&dst_ports);
|
sset_destroy(&dst_ports);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user