From: Ben Pfaff Date: Fri, 25 Mar 2011 20:00:13 +0000 (-0700) Subject: dpif: Use sset instead of svec in dpif interface. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d0c23a1a57f5bd994d3af124673a218e21528dd3;p=openvswitch dpif: Use sset instead of svec in dpif interface. --- diff --git a/lib/dpif-linux.c b/lib/dpif-linux.c index 3c22b556..bdc77036 100644 --- a/lib/dpif-linux.c +++ b/lib/dpif-linux.c @@ -46,7 +46,6 @@ #include "rtnetlink-link.h" #include "shash.h" #include "sset.h" -#include "svec.h" #include "unaligned.h" #include "util.h" #include "vlog.h" @@ -160,7 +159,7 @@ dpif_linux_cast(const struct dpif *dpif) } static int -dpif_linux_enumerate(struct svec *all_dps) +dpif_linux_enumerate(struct sset *all_dps) { struct nl_dump dump; struct ofpbuf msg; @@ -176,7 +175,7 @@ dpif_linux_enumerate(struct svec *all_dps) struct dpif_linux_dp dp; if (!dpif_linux_dp_from_ofpbuf(&dp, &msg)) { - svec_add(all_dps, dp.name); + sset_add(all_dps, dp.name); } } return nl_dump_done(&dump); diff --git a/lib/dpif-provider.h b/lib/dpif-provider.h index 91074d50..4d367530 100644 --- a/lib/dpif-provider.h +++ b/lib/dpif-provider.h @@ -86,7 +86,7 @@ struct dpif_class { * * Some kinds of datapaths might not be practically enumerable, in which * case this function may be a null pointer. */ - int (*enumerate)(struct svec *all_dps); + int (*enumerate)(struct sset *all_dps); /* Attempts to open an existing dpif called 'name', if 'create' is false, * or to open an existing dpif or create a new one, if 'create' is true. diff --git a/lib/dpif.c b/lib/dpif.c index a754613a..81e180fb 100644 --- a/lib/dpif.c +++ b/lib/dpif.c @@ -36,7 +36,7 @@ #include "packets.h" #include "poll-loop.h" #include "shash.h" -#include "svec.h" +#include "sset.h" #include "timeval.h" #include "util.h" #include "valgrind.h" @@ -184,36 +184,36 @@ dp_unregister_provider(const char *type) } /* Clears 'types' and enumerates the types of all currently registered datapath - * providers into it. The caller must first initialize the svec. */ + * providers into it. The caller must first initialize the sset. */ void -dp_enumerate_types(struct svec *types) +dp_enumerate_types(struct sset *types) { struct shash_node *node; dp_initialize(); - svec_clear(types); + sset_clear(types); SHASH_FOR_EACH(node, &dpif_classes) { const struct registered_dpif_class *registered_class = node->data; - svec_add(types, registered_class->dpif_class->type); + sset_add(types, registered_class->dpif_class->type); } } /* Clears 'names' and enumerates the names of all known created datapaths with - * the given 'type'. The caller must first initialize the svec. Returns 0 if + * the given 'type'. The caller must first initialize the sset. Returns 0 if * successful, otherwise a positive errno value. * * Some kinds of datapaths might not be practically enumerable. This is not * considered an error. */ int -dp_enumerate_names(const char *type, struct svec *names) +dp_enumerate_names(const char *type, struct sset *names) { const struct registered_dpif_class *registered_class; const struct dpif_class *dpif_class; int error; dp_initialize(); - svec_clear(names); + sset_clear(names); registered_class = shash_find_data(&dpif_classes, type); if (!registered_class) { diff --git a/lib/dpif.h b/lib/dpif.h index 8872a2ef..0e0f407c 100644 --- a/lib/dpif.h +++ b/lib/dpif.h @@ -34,7 +34,7 @@ struct ds; struct netdev; struct nlattr; struct ofpbuf; -struct svec; +struct sset; struct dpif_class; void dp_run(void); @@ -42,9 +42,9 @@ void dp_wait(void); int dp_register_provider(const struct dpif_class *); int dp_unregister_provider(const char *type); -void dp_enumerate_types(struct svec *types); +void dp_enumerate_types(struct sset *types); -int dp_enumerate_names(const char *type, struct svec *names); +int dp_enumerate_names(const char *type, struct sset *names); void dp_parse_name(const char *datapath_name, char **name, char **type); int dpif_open(const char *name, const char *type, struct dpif **); diff --git a/utilities/ovs-dpctl.c b/utilities/ovs-dpctl.c index 658f6ba1..f3e13a70 100644 --- a/utilities/ovs-dpctl.c +++ b/utilities/ovs-dpctl.c @@ -38,7 +38,7 @@ #include "netdev.h" #include "odp-util.h" #include "shash.h" -#include "svec.h" +#include "sset.h" #include "timeval.h" #include "util.h" #include "vlog.h" @@ -404,23 +404,21 @@ do_show(int argc, char *argv[]) } } } else { - struct svec types; + struct sset types; const char *type; - size_t i; - svec_init(&types); + sset_init(&types); dp_enumerate_types(&types); - SVEC_FOR_EACH (i, type, &types) { - struct svec names; + SSET_FOR_EACH (type, &types) { + struct sset names; const char *name; - size_t j; - svec_init(&names); + sset_init(&names); if (dp_enumerate_names(type, &names)) { failure = true; continue; } - SVEC_FOR_EACH (j, name, &names) { + SSET_FOR_EACH (name, &names) { struct dpif *dpif; int error; @@ -432,9 +430,9 @@ do_show(int argc, char *argv[]) failure = true; } } - svec_destroy(&names); + sset_destroy(&names); } - svec_destroy(&types); + sset_destroy(&types); } if (failure) { exit(EXIT_FAILURE); @@ -444,34 +442,34 @@ do_show(int argc, char *argv[]) static void do_dump_dps(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) { - struct svec dpif_names, dpif_types; - unsigned int i; + struct sset dpif_names, dpif_types; + const char *type; int error = 0; - svec_init(&dpif_names); - svec_init(&dpif_types); + sset_init(&dpif_names); + sset_init(&dpif_types); dp_enumerate_types(&dpif_types); - for (i = 0; i < dpif_types.n; i++) { - unsigned int j; + SSET_FOR_EACH (type, &dpif_types) { + const char *name; int retval; - retval = dp_enumerate_names(dpif_types.names[i], &dpif_names); + retval = dp_enumerate_names(type, &dpif_names); if (retval) { error = retval; } - for (j = 0; j < dpif_names.n; j++) { + SSET_FOR_EACH (name, &dpif_names) { struct dpif *dpif; - if (!dpif_open(dpif_names.names[j], dpif_types.names[i], &dpif)) { + if (!dpif_open(name, type, &dpif)) { printf("%s\n", dpif_name(dpif)); dpif_close(dpif); } } } - svec_destroy(&dpif_names); - svec_destroy(&dpif_types); + sset_destroy(&dpif_names); + sset_destroy(&dpif_types); if (error) { exit(EXIT_FAILURE); } diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c index 951ce74e..22af407b 100644 --- a/vswitchd/bridge.c +++ b/vswitchd/bridge.c @@ -375,7 +375,8 @@ bridge_configure_once(const struct ovsrec_open_vswitch *cfg) { static bool already_configured_once; struct svec bridge_names; - struct svec dpif_names, dpif_types; + struct sset dpif_names, dpif_types; + const char *type; size_t i; /* Only do this once per ovs-vswitchd run. */ @@ -395,22 +396,21 @@ bridge_configure_once(const struct ovsrec_open_vswitch *cfg) /* Iterate over all system dpifs and delete any of them that do not appear * in 'cfg'. */ - svec_init(&dpif_names); - svec_init(&dpif_types); + sset_init(&dpif_names); + sset_init(&dpif_types); dp_enumerate_types(&dpif_types); - for (i = 0; i < dpif_types.n; i++) { - size_t j; + SSET_FOR_EACH (type, &dpif_types) { + const char *name; - dp_enumerate_names(dpif_types.names[i], &dpif_names); + dp_enumerate_names(type, &dpif_names); /* Delete each dpif whose name is not in 'bridge_names'. */ - for (j = 0; j < dpif_names.n; j++) { - if (!svec_contains(&bridge_names, dpif_names.names[j])) { + SSET_FOR_EACH (name, &dpif_names) { + if (!svec_contains(&bridge_names, name)) { struct dpif *dpif; int retval; - retval = dpif_open(dpif_names.names[j], dpif_types.names[i], - &dpif); + retval = dpif_open(name, type, &dpif); if (!retval) { dpif_delete(dpif); dpif_close(dpif); @@ -419,8 +419,8 @@ bridge_configure_once(const struct ovsrec_open_vswitch *cfg) } } svec_destroy(&bridge_names); - svec_destroy(&dpif_names); - svec_destroy(&dpif_types); + sset_destroy(&dpif_names); + sset_destroy(&dpif_types); } /* Callback for iterate_and_prune_ifaces(). */