[ovs-dev] [db-ctl-base v2 2/3] db-ctl-base: do not require client to expose the "tables" variable

Andy Zhou azhou at nicira.com
Thu Jul 9 20:27:17 UTC 2015


Instead, client now pass it via the modified ctl_init() API.

Siigned-off-by: Andy Zhou <azhou at nicira.com>
---
 lib/db-ctl-base.c     | 8 +++++++-
 lib/db-ctl-base.h     | 8 ++------
 utilities/ovs-vsctl.c | 4 ++--
 vtep/vtep-ctl.c       | 4 ++--
 4 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/lib/db-ctl-base.c b/lib/db-ctl-base.c
index 64c01e6..659820b 100644
--- a/lib/db-ctl-base.c
+++ b/lib/db-ctl-base.c
@@ -46,6 +46,11 @@ VLOG_DEFINE_THIS_MODULE(db_ctl_base);
 struct ovsdb_idl *the_idl;
 struct ovsdb_idl_txn *the_idl_txn;
 
+/* Represents all tables in the schema.  User must define 'tables'
+ * in implementation and supply via clt_init().  The definition must end
+ * with an all-NULL entry. */
+static const struct ctl_table_class *tables;
+
 static struct shash all_commands = SHASH_INITIALIZER(&all_commands);
 static const struct ctl_table_class *get_table(const char *table_name);
 static void set_column(const struct ctl_table_class *,
@@ -1908,8 +1913,9 @@ ctl_register_commands(const struct ctl_command_syntax *commands)
 
 /* Registers the 'db_ctl_commands' to 'all_commands'. */
 void
-ctl_init(void)
+ctl_init(const struct ctl_table_class tables_[])
 {
+    tables = tables_;
     ctl_register_commands(db_ctl_commands);
     ctl_register_commands(db_ctl_show_command);
 }
diff --git a/lib/db-ctl-base.h b/lib/db-ctl-base.h
index 8d25fbe..684de11 100644
--- a/lib/db-ctl-base.h
+++ b/lib/db-ctl-base.h
@@ -53,7 +53,8 @@ struct table;
 extern struct ovsdb_idl *the_idl;
 extern struct ovsdb_idl_txn *the_idl_txn;
 
-void ctl_init(void);
+struct ctl_table_class;
+void ctl_init(const struct ctl_table_class *tables);
 char *ctl_default_db(void);
 OVS_NO_RETURN void ctl_exit(int status);
 OVS_NO_RETURN void ctl_fatal(const char *, ...) OVS_PRINTF_FORMAT(1, 2);
@@ -242,11 +243,6 @@ struct ctl_table_class {
     struct ctl_row_id row_ids[2];
 };
 
-/* Represents all tables in the schema.  User must define 'tables'
- * in implementation.  And the definition must end with an all-NULL
- * entry. */
-extern const struct ctl_table_class tables[];
-
 void ctl_set_column(const char *table_name,
                     const struct ovsdb_idl_row *, const char *arg,
                     struct ovsdb_symbol_table *);
diff --git a/utilities/ovs-vsctl.c b/utilities/ovs-vsctl.c
index 863bc73..8d62d54 100644
--- a/utilities/ovs-vsctl.c
+++ b/utilities/ovs-vsctl.c
@@ -2262,7 +2262,7 @@ cmd_get_aa_mapping(struct ctl_context *ctx)
 }
 
 
-const struct ctl_table_class tables[] = {
+static const struct ctl_table_class tables[] = {
     {&ovsrec_table_bridge,
      {{&ovsrec_table_bridge, &ovsrec_bridge_col_name, NULL},
       {&ovsrec_table_flow_sample_collector_set, NULL,
@@ -2749,6 +2749,6 @@ static const struct ctl_command_syntax vsctl_commands[] = {
 static void
 vsctl_cmd_init(void)
 {
-    ctl_init();
+    ctl_init(tables);
     ctl_register_commands(vsctl_commands);
 }
diff --git a/vtep/vtep-ctl.c b/vtep/vtep-ctl.c
index 7f455df..f065fc9 100644
--- a/vtep/vtep-ctl.c
+++ b/vtep/vtep-ctl.c
@@ -1962,7 +1962,7 @@ cmd_set_manager(struct ctl_context *ctx)
 }
 
 /* Parameter commands. */
-const struct ctl_table_class tables[] = {
+static const struct ctl_table_class tables[] = {
     {&vteprec_table_global,
      {{&vteprec_table_global, NULL, NULL},
       {NULL, NULL, NULL}}},
@@ -2310,6 +2310,6 @@ static const struct ctl_command_syntax vtep_commands[] = {
 static void
 vtep_ctl_cmd_init(void)
 {
-    ctl_init();
+    ctl_init(tables);
     ctl_register_commands(vtep_commands);
 }
-- 
1.9.1




More information about the dev mailing list