[ovs-dev] [sset 1/8] Convert shash users that don't use the 'data' value to sset instead.

Ben Pfaff blp at nicira.com
Fri Mar 25 22:40:43 UTC 2011


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.
---
 lib/dpif-linux.c      |   18 +++++-----
 lib/fatal-signal.c    |   24 ++++++--------
 lib/netdev.c          |   21 +++++-------
 ofproto/ofproto.c     |   17 +++++-----
 ovsdb/ovsdb-server.c  |   34 ++++++++++-----------
 utilities/ovs-vsctl.c |   31 ++++++++++---------
 vswitchd/bridge.c     |   80 ++++++++++++++++++++++++------------------------
 7 files changed, 109 insertions(+), 116 deletions(-)

diff --git a/lib/dpif-linux.c b/lib/dpif-linux.c
index 509174c..3c22b55 100644
--- a/lib/dpif-linux.c
+++ b/lib/dpif-linux.c
@@ -45,6 +45,7 @@
 #include "rtnetlink.h"
 #include "rtnetlink-link.h"
 #include "shash.h"
+#include "sset.h"
 #include "svec.h"
 #include "unaligned.h"
 #include "util.h"
@@ -125,7 +126,7 @@ struct dpif_linux {
     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;
 };
@@ -231,7 +232,7 @@ open_dpif(const struct dpif_linux_dp *dp, struct dpif **dpifp)
     }
     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;
 
@@ -247,7 +248,7 @@ dpif_linux_close(struct 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);
 }
 
@@ -483,11 +484,10 @@ dpif_linux_port_poll(const struct dpif *dpif_, char **devnamep)
 
     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;
@@ -498,7 +498,7 @@ static void
 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();
@@ -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
              * existing one. */
-            shash_add_once(&dpif->changed_ports, change->ifname, NULL);
+            sset_add(&dpif->changed_ports, change->ifname);
         }
     } else {
         dpif->change_error = true;
diff --git a/lib/fatal-signal.c b/lib/fatal-signal.c
index 81f8f28..ed82173 100644
--- a/lib/fatal-signal.c
+++ b/lib/fatal-signal.c
@@ -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");
  * you may not use this file except in compliance with the License.
@@ -26,6 +26,7 @@
 #include <unistd.h>
 #include "poll-loop.h"
 #include "shash.h"
+#include "sset.h"
 #include "socket-util.h"
 #include "util.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.) */
-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())? */
@@ -215,7 +216,7 @@ fatal_signal_add_file_to_unlink(const char *file)
         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
@@ -223,12 +224,7 @@ fatal_signal_add_file_to_unlink(const char *file)
 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'.
@@ -255,17 +251,17 @@ unlink_files(void *aux OVS_UNUSED)
 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);
     }
 }
 
diff --git a/lib/netdev.c b/lib/netdev.c
index f06742a..4254c1a 100644
--- a/lib/netdev.c
+++ b/lib/netdev.c
@@ -37,6 +37,7 @@
 #include "packets.h"
 #include "poll-loop.h"
 #include "shash.h"
+#include "sset.h"
 #include "svec.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. */
 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
@@ -1454,7 +1455,7 @@ netdev_monitor_create(void)
 {
     struct netdev_monitor *monitor = xmalloc(sizeof *monitor);
     shash_init(&monitor->polled_netdevs);
-    shash_init(&monitor->changed_netdevs);
+    sset_init(&monitor->changed_netdevs);
     return monitor;
 }
 
@@ -1472,7 +1473,7 @@ netdev_monitor_destroy(struct netdev_monitor *monitor)
         }
 
         shash_destroy(&monitor->polled_netdevs);
-        shash_destroy(&monitor->changed_netdevs);
+        sset_destroy(&monitor->changed_netdevs);
         free(monitor);
     }
 }
@@ -1482,7 +1483,7 @@ netdev_monitor_cb(struct netdev_notifier *notifier)
 {
     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
@@ -1526,10 +1527,7 @@ netdev_monitor_remove(struct netdev_monitor *monitor, struct netdev *netdev)
         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);
     }
 }
 
@@ -1543,12 +1541,11 @@ netdev_monitor_remove(struct netdev_monitor *monitor, struct netdev *netdev)
 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;
     }
 }
@@ -1559,7 +1556,7 @@ netdev_monitor_poll(struct netdev_monitor *monitor, char **devnamep)
 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
diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c
index e0715b9..5412f8e 100644
--- a/ofproto/ofproto.c
+++ b/ofproto/ofproto.c
@@ -54,6 +54,7 @@
 #include "poll-loop.h"
 #include "rconn.h"
 #include "shash.h"
+#include "sset.h"
 #include "stream-ssl.h"
 #include "svec.h"
 #include "tag.h"
@@ -1578,25 +1579,25 @@ static void
 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 *
diff --git a/ovsdb/ovsdb-server.c b/ovsdb/ovsdb-server.c
index 8d44d84..df0bc95 100644
--- a/ovsdb/ovsdb-server.c
+++ b/ovsdb/ovsdb-server.c
@@ -40,7 +40,7 @@
 #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"
@@ -64,15 +64,15 @@ static unixctl_cb_func ovsdb_server_compact;
 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
@@ -82,7 +82,7 @@ main(int argc, char *argv[])
     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;
@@ -171,7 +171,7 @@ main(int argc, char *argv[])
     }
     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)) {
@@ -551,14 +551,14 @@ update_remote_rows(const struct ovsdb *db, struct ovsdb_txn *txn,
 
 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);
@@ -566,8 +566,8 @@ update_remote_status(const struct ovsdb_jsonrpc_server *jsonrpc,
     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);
@@ -582,16 +582,14 @@ update_remote_status(const struct ovsdb_jsonrpc_server *jsonrpc,
 /* 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 {
@@ -652,7 +650,7 @@ ovsdb_server_reconnect(struct unixctl_conn *conn, const char *args OVS_UNUSED,
 
 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 {
@@ -684,7 +682,7 @@ parse_options(int argc, char *argv[], char **file_namep,
     };
     char *short_options = long_options_to_short_options(long_options);
 
-    shash_init(remotes);
+    sset_init(remotes);
     for (;;) {
         int c;
 
@@ -695,7 +693,7 @@ parse_options(int argc, char *argv[], char **file_namep,
 
         switch (c) {
         case OPT_REMOTE:
-            shash_add_once(remotes, optarg, NULL);
+            sset_add(remotes, optarg);
             break;
 
         case OPT_UNIXCTL:
diff --git a/utilities/ovs-vsctl.c b/utilities/ovs-vsctl.c
index 2baab00..fc410f8 100644
--- a/utilities/ovs-vsctl.c
+++ b/utilities/ovs-vsctl.c
@@ -38,6 +38,7 @@
 #include "process.h"
 #include "stream.h"
 #include "stream-ssl.h"
+#include "sset.h"
 #include "svec.h"
 #include "vswitchd/vswitch-idl.h"
 #include "table.h"
@@ -757,7 +758,7 @@ static void
 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;
@@ -765,14 +766,14 @@ get_info(struct vsctl_context *ctx, struct vsctl_info *info)
     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;
@@ -785,29 +786,29 @@ get_info(struct vsctl_context *ctx, struct vsctl_info *info)
         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);
@@ -816,12 +817,12 @@ get_info(struct vsctl_context *ctx, struct vsctl_info *info)
             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;
             }
 
@@ -855,8 +856,8 @@ get_info(struct vsctl_context *ctx, struct vsctl_info *info)
             }
         }
     }
-    shash_destroy(&bridges);
-    shash_destroy(&ports);
+    sset_destroy(&bridges);
+    sset_destroy(&ports);
 }
 
 static void
diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c
index b57860f..b071ec7 100644
--- a/vswitchd/bridge.c
+++ b/vswitchd/bridge.c
@@ -61,6 +61,7 @@
 #include "shash.h"
 #include "socket-util.h"
 #include "stream-ssl.h"
+#include "sset.h"
 #include "svec.h"
 #include "system-stats.h"
 #include "timeval.h"
@@ -142,8 +143,8 @@ struct mirror {
     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;
 
@@ -499,30 +500,29 @@ collect_in_band_managers(const struct ovsrec_open_vswitch *ovs_cfg,
 {
     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)
@@ -533,7 +533,7 @@ collect_in_band_managers(const struct ovsrec_open_vswitch *ovs_cfg,
             }
         }
     }
-    shash_destroy(&targets);
+    sset_destroy(&targets);
 
     *managersp = managers;
     *n_managersp = n_managers;
@@ -3928,24 +3928,24 @@ static void
 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
@@ -3969,7 +3969,7 @@ static void
 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;
@@ -4037,12 +4037,12 @@ port_reconfigure(struct port *port, const struct ovsrec_port *cfg)
     }
 
     /* 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);
@@ -4079,7 +4079,7 @@ port_reconfigure(struct port *port, const struct ovsrec_port *cfg)
             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");
@@ -4734,8 +4734,8 @@ mirror_create(struct bridge *br, struct ovsrec_mirror *cfg)
     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;
@@ -4756,8 +4756,8 @@ mirror_destroy(struct mirror *m)
             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;
@@ -4771,14 +4771,14 @@ mirror_destroy(struct mirror *m)
 
 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);
@@ -4836,7 +4836,7 @@ port_trunks_any_mirrored_vlan(const struct mirror *m, const struct port *p)
 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;
@@ -4876,12 +4876,12 @@ mirror_reconfigure_one(struct mirror *m, struct ovsrec_mirror *cfg)
         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;
@@ -4897,8 +4897,8 @@ mirror_reconfigure_one(struct mirror *m, struct ovsrec_mirror *cfg)
     }
 
     /* 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
@@ -4906,8 +4906,8 @@ mirror_reconfigure_one(struct mirror *m, struct ovsrec_mirror *cfg)
         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;
@@ -4917,7 +4917,7 @@ mirror_reconfigure_one(struct mirror *m, struct ovsrec_mirror *cfg)
     /* 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)
@@ -4927,7 +4927,7 @@ mirror_reconfigure_one(struct mirror *m, struct ovsrec_mirror *cfg)
             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;
@@ -4935,6 +4935,6 @@ mirror_reconfigure_one(struct mirror *m, struct ovsrec_mirror *cfg)
     }
 
     /* Clean up. */
-    shash_destroy(&src_ports);
-    shash_destroy(&dst_ports);
+    sset_destroy(&src_ports);
+    sset_destroy(&dst_ports);
 }
-- 
1.7.1




More information about the dev mailing list