[ovs-dev] [PATCH] Fully initialize data structures.
Linda Sun
lsun at vmware.com
Fri Jul 19 01:06:44 UTC 2013
Signed-off-by: Linda Sun <lsun at vmware.com>
---
lib/odp-util.c | 15 ++++++++-------
ofproto/ofproto-dpif-xlate.c | 10 +++++-----
ovsdb/ovsdb-client.c | 9 +++++++--
ovsdb/ovsdb-tool.c | 9 +++++++--
utilities/ovs-benchmark.c | 10 ++++++++--
utilities/ovs-dpctl.c | 9 +++++++--
utilities/ovs-ofctl.c | 9 +++++++--
utilities/ovs-vsctl.c | 10 +++++++---
8 files changed, 56 insertions(+), 25 deletions(-)
diff --git a/lib/odp-util.c b/lib/odp-util.c
index b233cbe..c12e2fe 100644
--- a/lib/odp-util.c
+++ b/lib/odp-util.c
@@ -143,9 +143,10 @@ format_generic_odp_action(struct ds *ds, const struct nlattr *a)
static void
format_odp_sample_action(struct ds *ds, const struct nlattr *attr)
{
- static const struct nl_policy ovs_sample_policy[] = {
- [OVS_SAMPLE_ATTR_PROBABILITY] = { .type = NL_A_U32 },
- [OVS_SAMPLE_ATTR_ACTIONS] = { .type = NL_A_NESTED }
+ static const struct nl_policy ovs_sample_policy[__OVS_SAMPLE_ATTR_MAX] = {
+ { NL_A_NO_ATTR, 0, 0, false}, /* OVS_SAMPLE_ATTR_UNSPEC */
+ { NL_A_U32, 0, 0, false}, /* OVS_SAMPLE_ATTR_PROBABILITY */
+ { NL_A_NESTED, 0, 0, false}, /* OVS_SAMPLE_ATTR_ACTIONS */
};
struct nlattr *a[ARRAY_SIZE(ovs_sample_policy)];
double percentage;
@@ -258,10 +259,10 @@ parse_flags(const char *s, const char *(*bit_to_string)(uint32_t),
static void
format_odp_userspace_action(struct ds *ds, const struct nlattr *attr)
{
- static const struct nl_policy ovs_userspace_policy[] = {
- [OVS_USERSPACE_ATTR_PID] = { .type = NL_A_U32 },
- [OVS_USERSPACE_ATTR_USERDATA] = { .type = NL_A_UNSPEC,
- .optional = true },
+ static const struct nl_policy ovs_userspace_policy[__OVS_USERSPACE_ATTR_MAX] = {
+ { NL_A_NO_ATTR, 0, 0, false}, /* OVS_USERSPACE_ATTR_UNSPEC */
+ { NL_A_U32, 0, 0, false}, /* OVS_USERSPACE_ATTR_PID */
+ { NL_A_UNSPEC, 0, 0, true}, /* OVS_USERSPACE_ATTR_USERDATA */
};
struct nlattr *a[ARRAY_SIZE(ovs_userspace_policy)];
const struct nlattr *userdata_attr;
diff --git a/ofproto/ofproto-dpif-xlate.c b/ofproto/ofproto-dpif-xlate.c
index 0507f8e..2e4a1f3 100644
--- a/ofproto/ofproto-dpif-xlate.c
+++ b/ofproto/ofproto-dpif-xlate.c
@@ -160,11 +160,9 @@ struct xlate_ctx {
* it did not arrive on a "real" port. 'ofpp_none_bundle' exists for
* when an input bundle is needed for validation (e.g., mirroring or
* OFPP_NORMAL processing). It is not connected to an 'ofproto' or have
- * any 'port' structs, so care must be taken when dealing with it. */
-static struct xbundle ofpp_none_bundle = {
- .name = "OFPP_NONE",
- .vlan_mode = PORT_VLAN_TRUNK
-};
+ * any 'port' structs, so care must be taken when dealing with it.
+ * The bundle's name and vlan mode are initialized in lookup_input_bundle() */
+static struct xbundle ofpp_none_bundle;
static struct hmap xbridges = HMAP_INITIALIZER(&xbridges);
static struct hmap xbundles = HMAP_INITIALIZER(&xbundles);
@@ -530,6 +528,8 @@ lookup_input_bundle(const struct xbridge *xbridge, ofp_port_t in_port,
/* Special-case OFPP_NONE, which a controller may use as the ingress
* port for traffic that it is sourcing. */
if (in_port == OFPP_NONE) {
+ ofpp_none_bundle.name = "OFPP_NONE";
+ ofpp_none_bundle.vlan_mode = PORT_VLAN_TRUNK;
return &ofpp_none_bundle;
}
diff --git a/ovsdb/ovsdb-client.c b/ovsdb/ovsdb-client.c
index c25148d..67d09cb 100644
--- a/ovsdb/ovsdb-client.c
+++ b/ovsdb/ovsdb-client.c
@@ -69,7 +69,7 @@ static bool timestamp;
/* Format for table output. */
static struct table_style table_style = TABLE_STYLE_DEFAULT;
-static const struct ovsdb_client_command all_commands[];
+static const struct ovsdb_client_command *get_all_commands(void);
static void usage(void) NO_RETURN;
static void parse_options(int argc, char *argv[]);
@@ -92,7 +92,7 @@ main(int argc, char *argv[])
ovs_fatal(0, "missing command name; use --help for help");
}
- for (command = all_commands; ; command++) {
+ for (command = get_all_commands(); ; command++) {
if (!command->name) {
VLOG_FATAL("unknown command '%s'; use --help for help",
argv[optind]);
@@ -997,3 +997,8 @@ static const struct ovsdb_client_command all_commands[] = {
{ NULL, 0, 0, 0, NULL },
};
+
+static const struct ovsdb_client_command *get_all_commands(void)
+{
+ return all_commands;
+}
diff --git a/ovsdb/ovsdb-tool.c b/ovsdb/ovsdb-tool.c
index a8febda..7cd0485 100644
--- a/ovsdb/ovsdb-tool.c
+++ b/ovsdb/ovsdb-tool.c
@@ -45,7 +45,7 @@ VLOG_DEFINE_THIS_MODULE(ovsdb_tool);
/* -m, --more: Verbosity level for "show-log" command output. */
static int show_log_verbosity;
-static const struct command all_commands[];
+static const struct command *get_all_commands(void);
static void usage(void) NO_RETURN;
static void parse_options(int argc, char *argv[]);
@@ -59,7 +59,7 @@ main(int argc, char *argv[])
set_program_name(argv[0]);
parse_options(argc, argv);
signal(SIGPIPE, SIG_IGN);
- run_command(argc - optind, argv + optind, all_commands);
+ run_command(argc - optind, argv + optind, get_all_commands());
return 0;
}
@@ -564,3 +564,8 @@ static const struct command all_commands[] = {
{ "help", 0, INT_MAX, do_help },
{ NULL, 0, 0, NULL },
};
+
+static const struct command *get_all_commands(void)
+{
+ return all_commands;
+}
diff --git a/utilities/ovs-benchmark.c b/utilities/ovs-benchmark.c
index d1bdaac..165c366 100644
--- a/utilities/ovs-benchmark.c
+++ b/utilities/ovs-benchmark.c
@@ -49,7 +49,7 @@ static double max_rate;
static double timeout;
-static const struct command all_commands[];
+static const struct command *get_all_commands(void);
static void parse_options(int argc, char *argv[]);
static void usage(void);
@@ -72,7 +72,7 @@ main(int argc, char *argv[])
set_program_name(argv[0]);
vlog_set_levels(NULL, VLF_ANY_FACILITY, VLL_EMER);
parse_options(argc, argv);
- run_command(argc - optind, argv + optind, all_commands);
+ run_command(argc - optind, argv + optind, get_all_commands());
return 0;
}
@@ -617,3 +617,9 @@ static const struct command all_commands[] = {
{ "help", 0, 0, cmd_help },
{ NULL, 0, 0, NULL },
};
+
+static const struct command *get_all_commands(void)
+{
+ return all_commands;
+}
+
diff --git a/utilities/ovs-dpctl.c b/utilities/ovs-dpctl.c
index 2389942..e285ed5 100644
--- a/utilities/ovs-dpctl.c
+++ b/utilities/ovs-dpctl.c
@@ -66,7 +66,7 @@ static bool may_create;
* the option itself. */
static int verbosity;
-static const struct command all_commands[];
+static const struct command *get_all_commands(void);
static void usage(void) NO_RETURN;
static void parse_options(int argc, char *argv[]);
@@ -77,7 +77,7 @@ main(int argc, char *argv[])
set_program_name(argv[0]);
parse_options(argc, argv);
signal(SIGPIPE, SIG_IGN);
- run_command(argc - optind, argv + optind, all_commands);
+ run_command(argc - optind, argv + optind, get_all_commands());
return 0;
}
@@ -1146,3 +1146,8 @@ static const struct command all_commands[] = {
{ NULL, 0, 0, NULL },
};
+
+static const struct command *get_all_commands(void)
+{
+ return all_commands;
+}
diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c
index 4d5a84e..2622255 100644
--- a/utilities/ovs-ofctl.c
+++ b/utilities/ovs-ofctl.c
@@ -98,7 +98,7 @@ struct sort_criterion {
static struct sort_criterion *criteria;
static size_t n_criteria, allocated_criteria;
-static const struct command all_commands[];
+static const struct command *get_all_commands(void);
static void usage(void) NO_RETURN;
static void parse_options(int argc, char *argv[]);
@@ -113,7 +113,7 @@ main(int argc, char *argv[])
set_program_name(argv[0]);
parse_options(argc, argv);
signal(SIGPIPE, SIG_IGN);
- run_command(argc - optind, argv + optind, all_commands);
+ run_command(argc - optind, argv + optind, get_all_commands());
return 0;
}
@@ -2956,3 +2956,8 @@ static const struct command all_commands[] = {
{ NULL, 0, 0, NULL },
};
+
+static const struct command *get_all_commands(void)
+{
+ return all_commands;
+}
diff --git a/utilities/ovs-vsctl.c b/utilities/ovs-vsctl.c
index e679e0d..0527885 100644
--- a/utilities/ovs-vsctl.c
+++ b/utilities/ovs-vsctl.c
@@ -128,7 +128,7 @@ static bool retry;
static struct table_style table_style = TABLE_STYLE_DEFAULT;
/* All supported commands. */
-static const struct vsctl_command_syntax all_commands[];
+static const struct vsctl_command_syntax *get_all_commands(void);
/* The IDL we're using and the current transaction, if any.
* This is for use by vsctl_exit() only, to allow it to clean up.
@@ -302,7 +302,7 @@ parse_options(int argc, char *argv[], struct shash *local_options)
options = xmemdup(global_long_options, sizeof global_long_options);
allocated_options = ARRAY_SIZE(global_long_options);
n_options = n_global_long_options;
- for (p = all_commands; p->name; p++) {
+ for (p = get_all_commands(); p->name; p++) {
if (p->options[0]) {
char *save_ptr = NULL;
char *name;
@@ -568,7 +568,7 @@ find_command(const char *name)
if (shash_is_empty(&commands)) {
const struct vsctl_command_syntax *p;
- for (p = all_commands; p->name; p++) {
+ for (p = get_all_commands(); p->name; p++) {
shash_add_assert(&commands, p->name, p);
}
}
@@ -4228,3 +4228,7 @@ static const struct vsctl_command_syntax all_commands[] = {
{NULL, 0, 0, NULL, NULL, NULL, NULL, RO},
};
+static const struct vsctl_command_syntax *get_all_commands(void)
+{
+ return all_commands;
+}
--
1.7.9.5
More information about the dev
mailing list