[ovs-dev] db
___ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev
[ovs-dev] db
___ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev
Re: [ovs-dev] [db-ctl-base v2 1/3] db-ctl-base: do not expose get_table() API
nitpick, could we move this deletion to next commit? Make sense. I moved it. Acked-by: Alex Wang al...@nicira.com Thanks for the review. Pushed to master. /* ctl_fatal() also logs the error, so it is preferred in this file. */ @@ -250,9 +247,8 @@ struct ctl_table_class { * entry. */ extern const struct ctl_table_class tables[]; -const struct ctl_table_class *get_table(const char *table_name); -void set_column(const struct ctl_table_class *, -const struct ovsdb_idl_row *, const char *arg, -struct ovsdb_symbol_table *); +void ctl_set_column(const char *table_name, +const struct ovsdb_idl_row *, const char *arg, +struct ovsdb_symbol_table *); #endif /* db-ctl-base.h */ diff --git a/utilities/ovs-vsctl.c b/utilities/ovs-vsctl.c index c9af355..863bc73 100644 --- a/utilities/ovs-vsctl.c +++ b/utilities/ovs-vsctl.c @@ -1556,8 +1556,8 @@ add_port(struct ctl_context *ctx, } for (i = 0; i n_settings; i++) { -set_column(get_table(Port), port-header_, settings[i], - ctx-symtab); +ctl_set_column(Port, port-header_, settings[i], + ctx-symtab); } bridge_insert_port((bridge-parent ? bridge-parent-br_cfg -- 1.9.1 ___ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev ___ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev
Re: [ovs-dev] [db-ctl-base v2 1/3] db-ctl-base: do not expose get_table() API
On Thu, Jul 9, 2015 at 1:27 PM, Andy Zhou az...@nicira.com wrote: Both get_table() and set_cloum() APIs are mostly used within db-ctl-base library. This patch makes both private to the library. Add a new ctl_set_colum() API for library client. The changes are cleanups. No functional changes. Signed-off-by: Andy Zhou az...@nicira.com --- lib/db-ctl-base.c | 15 +-- lib/db-ctl-base.h | 10 +++--- utilities/ovs-vsctl.c | 4 ++-- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/lib/db-ctl-base.c b/lib/db-ctl-base.c index 10884b4..64c01e6 100644 --- a/lib/db-ctl-base.c +++ b/lib/db-ctl-base.c @@ -47,6 +47,10 @@ struct ovsdb_idl *the_idl; struct ovsdb_idl_txn *the_idl_txn; 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 *, + const struct ovsdb_idl_row *, const char *, + struct ovsdb_symbol_table *); static struct option * @@ -1990,7 +1994,7 @@ ctl_context_done(struct ctl_context *ctx, /* Finds and returns the struct ctl_table_class * with 'table_name' by * searching the 'tables'. */ -const struct ctl_table_class * +static const struct ctl_table_class * get_table(const char *table_name) { const struct ctl_table_class *table; @@ -2018,7 +2022,7 @@ get_table(const char *table_name) } /* Sets the column of 'row' in 'table'. */ -void +static void set_column(const struct ctl_table_class *table, const struct ovsdb_idl_row *row, const char *arg, struct ovsdb_symbol_table *symtab) @@ -2070,3 +2074,10 @@ set_column(const struct ctl_table_class *table, free(key_string); free(value_string); } + +void ctl_set_column(const char *table_name, +const struct ovsdb_idl_row *row, const char *arg, +struct ovsdb_symbol_table *symtab) +{ +set_column(get_table(table_name), row, arg, symtab); +} diff --git a/lib/db-ctl-base.h b/lib/db-ctl-base.h index f14d27f..8d25fbe 100644 --- a/lib/db-ctl-base.h +++ b/lib/db-ctl-base.h @@ -43,9 +43,6 @@ struct table; * - the *ctl command context by inheriting the 'struct ctl_context' for * additional commands implemented by user. (See 'struct ctl_context' for * more info) - * - * - the 'tables[]' for each table in the schema. - * */ nitpick, could we move this deletion to next commit? Acked-by: Alex Wang al...@nicira.com /* ctl_fatal() also logs the error, so it is preferred in this file. */ @@ -250,9 +247,8 @@ struct ctl_table_class { * entry. */ extern const struct ctl_table_class tables[]; -const struct ctl_table_class *get_table(const char *table_name); -void set_column(const struct ctl_table_class *, -const struct ovsdb_idl_row *, const char *arg, -struct ovsdb_symbol_table *); +void ctl_set_column(const char *table_name, +const struct ovsdb_idl_row *, const char *arg, +struct ovsdb_symbol_table *); #endif /* db-ctl-base.h */ diff --git a/utilities/ovs-vsctl.c b/utilities/ovs-vsctl.c index c9af355..863bc73 100644 --- a/utilities/ovs-vsctl.c +++ b/utilities/ovs-vsctl.c @@ -1556,8 +1556,8 @@ add_port(struct ctl_context *ctx, } for (i = 0; i n_settings; i++) { -set_column(get_table(Port), port-header_, settings[i], - ctx-symtab); +ctl_set_column(Port, port-header_, settings[i], + ctx-symtab); } bridge_insert_port((bridge-parent ? bridge-parent-br_cfg -- 1.9.1 ___ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev ___ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev
Re: [ovs-dev] [db-ctl-base v2 2/3] db-ctl-base: do not require client to expose the tables variable
Acked-by: Alex Wang al...@nicira.com On Thu, Jul 9, 2015 at 1:27 PM, Andy Zhou az...@nicira.com wrote: Instead, client now pass it via the modified ctl_init() API. Siigned-off-by: Andy Zhou az...@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 ___ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev ___ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev
Re: [ovs-dev] [db-ctl-base v2 3/3] db-ctl-base: group static functions together
Acked-by: Alex Wang al...@nicira.com On Thu, Jul 9, 2015 at 1:27 PM, Andy Zhou az...@nicira.com wrote: This file follows a convention that all static functions are grouped towards the beginning, ahead of public functions. Re-arrange the code to confirm to this convention. No functional changes. Signed-off-by: Andy Zhou az...@nicira.com --- lib/db-ctl-base.c | 166 +++--- 1 file changed, 83 insertions(+), 83 deletions(-) diff --git a/lib/db-ctl-base.c b/lib/db-ctl-base.c index 659820b..86a87d0 100644 --- a/lib/db-ctl-base.c +++ b/lib/db-ctl-base.c @@ -988,6 +988,35 @@ cmd_list(struct ctl_context *ctx) free(columns); } +/* Finds and returns the struct ctl_table_class * with 'table_name' by + * searching the 'tables'. */ +static const struct ctl_table_class * +get_table(const char *table_name) +{ +const struct ctl_table_class *table; +const struct ctl_table_class *best_match = NULL; +unsigned int best_score = 0; + +for (table = tables; table-class; table++) { +unsigned int score = score_partial_match(table-class-name, + table_name); +if (score best_score) { +best_match = table; +best_score = score; +} else if (score == best_score) { +best_match = NULL; +} +} +if (best_match) { +return best_match; +} else if (best_score) { +ctl_fatal(multiple table names match \%s\, table_name); +} else { +ctl_fatal(unknown table \%s\, table_name); +} +return NULL; +} + static void pre_cmd_find(struct ctl_context *ctx) { @@ -1034,6 +1063,60 @@ cmd_find(struct ctl_context *ctx) free(columns); } +/* Sets the column of 'row' in 'table'. */ +static void +set_column(const struct ctl_table_class *table, + const struct ovsdb_idl_row *row, const char *arg, + struct ovsdb_symbol_table *symtab) +{ +const struct ovsdb_idl_column *column; +char *key_string, *value_string; +char *error; + +error = parse_column_key_value(arg, table, column, key_string, + NULL, NULL, 0, value_string); +die_if_error(error); +if (!value_string) { +ctl_fatal(%s: missing value, arg); +} +check_mutable(row, column); + +if (key_string) { +union ovsdb_atom key, value; +struct ovsdb_datum datum; + +if (column-type.value.type == OVSDB_TYPE_VOID) { +ctl_fatal(cannot specify key to set for non-map column %s, + column-name); +} + +die_if_error(ovsdb_atom_from_string(key, column-type.key, +key_string, symtab)); +die_if_error(ovsdb_atom_from_string(value, column-type.value, +value_string, symtab)); + +ovsdb_datum_init_empty(datum); +ovsdb_datum_add_unsafe(datum, key, value, column-type); + +ovsdb_atom_destroy(key, column-type.key.type); +ovsdb_atom_destroy(value, column-type.value.type); + +ovsdb_datum_union(datum, ovsdb_idl_read(row, column), + column-type, false); +ovsdb_idl_txn_verify(row, column); +ovsdb_idl_txn_write(row, column, datum); +} else { +struct ovsdb_datum datum; + +die_if_error(ovsdb_datum_from_string(datum, column-type, + value_string, symtab)); +ovsdb_idl_txn_write(row, column, datum); +} + +free(key_string); +free(value_string); +} + static void pre_cmd_set(struct ctl_context *ctx) { @@ -1998,89 +2081,6 @@ ctl_context_done(struct ctl_context *ctx, invalidate_cache(ctx); } -/* Finds and returns the struct ctl_table_class * with 'table_name' by - * searching the 'tables'. */ -static const struct ctl_table_class * -get_table(const char *table_name) -{ -const struct ctl_table_class *table; -const struct ctl_table_class *best_match = NULL; -unsigned int best_score = 0; - -for (table = tables; table-class; table++) { -unsigned int score = score_partial_match(table-class-name, - table_name); -if (score best_score) { -best_match = table; -best_score = score; -} else if (score == best_score) { -best_match = NULL; -} -} -if (best_match) { -return best_match; -} else if (best_score) { -ctl_fatal(multiple table names match \%s\, table_name); -} else { -ctl_fatal(unknown table \%s\, table_name); -} -return NULL; -} - -/* Sets the column of 'row' in 'table'. */ -static void -set_column(const struct ctl_table_class *table, - const struct ovsdb_idl_row *row,
[ovs-dev] [db-ctl-base v2 3/3] db-ctl-base: group static functions together
This file follows a convention that all static functions are grouped towards the beginning, ahead of public functions. Re-arrange the code to confirm to this convention. No functional changes. Signed-off-by: Andy Zhou az...@nicira.com --- lib/db-ctl-base.c | 166 +++--- 1 file changed, 83 insertions(+), 83 deletions(-) diff --git a/lib/db-ctl-base.c b/lib/db-ctl-base.c index 659820b..86a87d0 100644 --- a/lib/db-ctl-base.c +++ b/lib/db-ctl-base.c @@ -988,6 +988,35 @@ cmd_list(struct ctl_context *ctx) free(columns); } +/* Finds and returns the struct ctl_table_class * with 'table_name' by + * searching the 'tables'. */ +static const struct ctl_table_class * +get_table(const char *table_name) +{ +const struct ctl_table_class *table; +const struct ctl_table_class *best_match = NULL; +unsigned int best_score = 0; + +for (table = tables; table-class; table++) { +unsigned int score = score_partial_match(table-class-name, + table_name); +if (score best_score) { +best_match = table; +best_score = score; +} else if (score == best_score) { +best_match = NULL; +} +} +if (best_match) { +return best_match; +} else if (best_score) { +ctl_fatal(multiple table names match \%s\, table_name); +} else { +ctl_fatal(unknown table \%s\, table_name); +} +return NULL; +} + static void pre_cmd_find(struct ctl_context *ctx) { @@ -1034,6 +1063,60 @@ cmd_find(struct ctl_context *ctx) free(columns); } +/* Sets the column of 'row' in 'table'. */ +static void +set_column(const struct ctl_table_class *table, + const struct ovsdb_idl_row *row, const char *arg, + struct ovsdb_symbol_table *symtab) +{ +const struct ovsdb_idl_column *column; +char *key_string, *value_string; +char *error; + +error = parse_column_key_value(arg, table, column, key_string, + NULL, NULL, 0, value_string); +die_if_error(error); +if (!value_string) { +ctl_fatal(%s: missing value, arg); +} +check_mutable(row, column); + +if (key_string) { +union ovsdb_atom key, value; +struct ovsdb_datum datum; + +if (column-type.value.type == OVSDB_TYPE_VOID) { +ctl_fatal(cannot specify key to set for non-map column %s, + column-name); +} + +die_if_error(ovsdb_atom_from_string(key, column-type.key, +key_string, symtab)); +die_if_error(ovsdb_atom_from_string(value, column-type.value, +value_string, symtab)); + +ovsdb_datum_init_empty(datum); +ovsdb_datum_add_unsafe(datum, key, value, column-type); + +ovsdb_atom_destroy(key, column-type.key.type); +ovsdb_atom_destroy(value, column-type.value.type); + +ovsdb_datum_union(datum, ovsdb_idl_read(row, column), + column-type, false); +ovsdb_idl_txn_verify(row, column); +ovsdb_idl_txn_write(row, column, datum); +} else { +struct ovsdb_datum datum; + +die_if_error(ovsdb_datum_from_string(datum, column-type, + value_string, symtab)); +ovsdb_idl_txn_write(row, column, datum); +} + +free(key_string); +free(value_string); +} + static void pre_cmd_set(struct ctl_context *ctx) { @@ -1998,89 +2081,6 @@ ctl_context_done(struct ctl_context *ctx, invalidate_cache(ctx); } -/* Finds and returns the struct ctl_table_class * with 'table_name' by - * searching the 'tables'. */ -static const struct ctl_table_class * -get_table(const char *table_name) -{ -const struct ctl_table_class *table; -const struct ctl_table_class *best_match = NULL; -unsigned int best_score = 0; - -for (table = tables; table-class; table++) { -unsigned int score = score_partial_match(table-class-name, - table_name); -if (score best_score) { -best_match = table; -best_score = score; -} else if (score == best_score) { -best_match = NULL; -} -} -if (best_match) { -return best_match; -} else if (best_score) { -ctl_fatal(multiple table names match \%s\, table_name); -} else { -ctl_fatal(unknown table \%s\, table_name); -} -return NULL; -} - -/* Sets the column of 'row' in 'table'. */ -static void -set_column(const struct ctl_table_class *table, - const struct ovsdb_idl_row *row, const char *arg, - struct ovsdb_symbol_table *symtab) -{ -const struct ovsdb_idl_column *column; -char *key_string, *value_string; -char *error; - -error = parse_column_key_value(arg, table, column, key_string, -
[ovs-dev] [db-ctl-base v2 1/3] db-ctl-base: do not expose get_table() API
Both get_table() and set_cloum() APIs are mostly used within db-ctl-base library. This patch makes both private to the library. Add a new ctl_set_colum() API for library client. The changes are cleanups. No functional changes. Signed-off-by: Andy Zhou az...@nicira.com --- lib/db-ctl-base.c | 15 +-- lib/db-ctl-base.h | 10 +++--- utilities/ovs-vsctl.c | 4 ++-- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/lib/db-ctl-base.c b/lib/db-ctl-base.c index 10884b4..64c01e6 100644 --- a/lib/db-ctl-base.c +++ b/lib/db-ctl-base.c @@ -47,6 +47,10 @@ struct ovsdb_idl *the_idl; struct ovsdb_idl_txn *the_idl_txn; 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 *, + const struct ovsdb_idl_row *, const char *, + struct ovsdb_symbol_table *); static struct option * @@ -1990,7 +1994,7 @@ ctl_context_done(struct ctl_context *ctx, /* Finds and returns the struct ctl_table_class * with 'table_name' by * searching the 'tables'. */ -const struct ctl_table_class * +static const struct ctl_table_class * get_table(const char *table_name) { const struct ctl_table_class *table; @@ -2018,7 +2022,7 @@ get_table(const char *table_name) } /* Sets the column of 'row' in 'table'. */ -void +static void set_column(const struct ctl_table_class *table, const struct ovsdb_idl_row *row, const char *arg, struct ovsdb_symbol_table *symtab) @@ -2070,3 +2074,10 @@ set_column(const struct ctl_table_class *table, free(key_string); free(value_string); } + +void ctl_set_column(const char *table_name, +const struct ovsdb_idl_row *row, const char *arg, +struct ovsdb_symbol_table *symtab) +{ +set_column(get_table(table_name), row, arg, symtab); +} diff --git a/lib/db-ctl-base.h b/lib/db-ctl-base.h index f14d27f..8d25fbe 100644 --- a/lib/db-ctl-base.h +++ b/lib/db-ctl-base.h @@ -43,9 +43,6 @@ struct table; * - the *ctl command context by inheriting the 'struct ctl_context' for * additional commands implemented by user. (See 'struct ctl_context' for * more info) - * - * - the 'tables[]' for each table in the schema. - * */ /* ctl_fatal() also logs the error, so it is preferred in this file. */ @@ -250,9 +247,8 @@ struct ctl_table_class { * entry. */ extern const struct ctl_table_class tables[]; -const struct ctl_table_class *get_table(const char *table_name); -void set_column(const struct ctl_table_class *, -const struct ovsdb_idl_row *, const char *arg, -struct ovsdb_symbol_table *); +void ctl_set_column(const char *table_name, +const struct ovsdb_idl_row *, const char *arg, +struct ovsdb_symbol_table *); #endif /* db-ctl-base.h */ diff --git a/utilities/ovs-vsctl.c b/utilities/ovs-vsctl.c index c9af355..863bc73 100644 --- a/utilities/ovs-vsctl.c +++ b/utilities/ovs-vsctl.c @@ -1556,8 +1556,8 @@ add_port(struct ctl_context *ctx, } for (i = 0; i n_settings; i++) { -set_column(get_table(Port), port-header_, settings[i], - ctx-symtab); +ctl_set_column(Port, port-header_, settings[i], + ctx-symtab); } bridge_insert_port((bridge-parent ? bridge-parent-br_cfg -- 1.9.1 ___ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev
[ovs-dev] [db-ctl-base v2 0/3] db-ctl-base cleanup
Minor cleanups in db-ctl-base library, and in prepare for ovsdb join related changes in the library. v1-v2: Drop the first patch that has been committed. group static functions together Fix comments Andy Zhou (3): db-ctl-base: do not expose get_table() API db-ctl-base: do not require client to expose the tables variable db-ctl-base: group static functions together lib/db-ctl-base.c | 179 +++--- lib/db-ctl-base.h | 18 ++--- utilities/ovs-vsctl.c | 8 +-- vtep/vtep-ctl.c | 4 +- 4 files changed, 109 insertions(+), 100 deletions(-) -- 1.9.1 ___ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev
[ovs-dev] [db-ctl-base v2 2/3] db-ctl-base: do not require client to expose the tables variable
Instead, client now pass it via the modified ctl_init() API. Siigned-off-by: Andy Zhou az...@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 ___ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev
Re: [ovs-dev] [db-backup 4/5] ovsdb-tool: New command needs-conversion.
Looks Good. On Tue, Feb 8, 2011 at 4:00 PM, Ben Pfaff b...@nicira.com wrote: --- ovsdb/ovsdb-tool.1.in | 7 +++ ovsdb/ovsdb-tool.c | 15 +++ ovsdb/ovsdb.c | 17 + ovsdb/ovsdb.h | 3 +++ tests/ovsdb-tool.at | 22 ++ 5 files changed, 64 insertions(+), 0 deletions(-) diff --git a/ovsdb/ovsdb-tool.1.in b/ovsdb/ovsdb-tool.1.in index 79bd2a6..7f34609 100644 --- a/ovsdb/ovsdb-tool.1.in +++ b/ovsdb/ovsdb-tool.1.in @@ -19,6 +19,8 @@ ovsdb\-tool \- Open vSwitch database management utility \fBovsdb\-tool \fR[\fIoptions\fR] \fBconvert\fI db schema \fR[\fItarget\fR] .br +\fBovsdb\-tool \fR[\fIoptions\fR] \fBneeds\-conversion\fI db schema\fR +.br \fBovsdb\-tool \fR[\fIoptions\fR] \fBdb\-version\fI db\fR .br \fBovsdb\-tool \fR[\fIoptions\fR] \fBschema\-version\fI schema\fR @@ -76,6 +78,11 @@ ignored. Columns that exist in \fIschema\fR but not in \fIdb\fR are set to their default values. All of \fIschema\fR's constraints apply in full. . +.IP \fBneeds\-conversion\fI db schema\fR +Reads the schema embedded in \fIdb\fR and the standalone schema in +\fIschema\fR and compares them. If the schemas are the same, prints +\fBno\fR on stdout; if they differ, print \fByes\fR. +. .IP \fBdb\-version\fI db\fR .IQ \fBschema\-version\fI schema\fR Prints the version number in the schema embedded within the database diff --git a/ovsdb/ovsdb-tool.c b/ovsdb/ovsdb-tool.c index 3730e67..4f55b6a 100644 --- a/ovsdb/ovsdb-tool.c +++ b/ovsdb/ovsdb-tool.c @@ -244,6 +244,20 @@ do_convert(int argc OVS_UNUSED, char *argv[]) } static void +do_needs_conversion(int argc OVS_UNUSED, char *argv[]) +{ + const char *db_file_name = argv[1]; + const char *schema_file_name = argv[2]; + struct ovsdb_schema *schema1, *schema2; + + check_ovsdb_error(ovsdb_file_read_schema(db_file_name, schema1)); + check_ovsdb_error(ovsdb_schema_from_file(schema_file_name, schema2)); + puts(ovsdb_schema_equal(schema1, schema2) ? no : yes); + ovsdb_schema_destroy(schema1); + ovsdb_schema_destroy(schema2); +} + +static void do_db_version(int argc OVS_UNUSED, char *argv[]) { const char *db_file_name = argv[1]; @@ -458,6 +472,7 @@ static const struct command all_commands[] = { { create, 2, 2, do_create }, { compact, 1, 2, do_compact }, { convert, 2, 3, do_convert }, + { needs-conversion, 2, 2, do_needs_conversion }, { db-version, 1, 1, do_db_version }, { db-cksum, 1, 1, do_db_cksum }, { schema-version, 1, 1, do_schema_version }, diff --git a/ovsdb/ovsdb.c b/ovsdb/ovsdb.c index 46d06a0..2a54a7b 100644 --- a/ovsdb/ovsdb.c +++ b/ovsdb/ovsdb.c @@ -235,6 +235,23 @@ ovsdb_schema_to_json(const struct ovsdb_schema *schema) return json; } + +/* Returns true if 'a' and 'b' specify equivalent schemas, false if they + * differ. */ +bool +ovsdb_schema_equal(const struct ovsdb_schema *a, + const struct ovsdb_schema *b) +{ + /* This implementation is simple, stupid, and slow, but I doubt that it + * will ever require much maintenance. */ + struct json *ja = ovsdb_schema_to_json(a); + struct json *jb = ovsdb_schema_to_json(b); + bool equals = json_equal(ja, jb); + json_destroy(ja); + json_destroy(jb); + + return equals; +} static void ovsdb_set_ref_table(const struct shash *tables, diff --git a/ovsdb/ovsdb.h b/ovsdb/ovsdb.h index ae743bb..834ff1a 100644 --- a/ovsdb/ovsdb.h +++ b/ovsdb/ovsdb.h @@ -47,6 +47,9 @@ struct ovsdb_error *ovsdb_schema_from_json(struct json *, struct ovsdb_schema **) WARN_UNUSED_RESULT; struct json *ovsdb_schema_to_json(const struct ovsdb_schema *); + +bool ovsdb_schema_equal(const struct ovsdb_schema *, + const struct ovsdb_schema *); /* Database. */ struct ovsdb { diff --git a/tests/ovsdb-tool.at b/tests/ovsdb-tool.at index 0f11668..989159d 100644 --- a/tests/ovsdb-tool.at +++ b/tests/ovsdb-tool.at @@ -306,3 +306,25 @@ AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore]) AT_CHECK([ovsdb-tool db-cksum db], [0], [12345678 9 ]) AT_CLEANUP + +AT_SETUP([ovsdb-tool needs-conversion (no conversion needed)]) +AT_KEYWORDS([ovsdb file positive]) +AT_DATA([schema], [ORDINAL_SCHEMA +]) +touch .db.~lock~ +AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore]) +AT_CHECK([ovsdb-tool needs-conversion db schema], [0], [no +]) +AT_CLEANUP + +AT_SETUP([ovsdb-tool needs-conversion (conversion needed)]) +AT_KEYWORDS([ovsdb file positive]) +AT_DATA([schema], [ORDINAL_SCHEMA +]) +touch .db.~lock~ +AT_CHECK([ovsdb-tool create db schema], [0], [], [ignore]) +sed 's/5\.1\.3/5.1.4/' schema schema2 +AT_CHECK([diff schema schema2], [1], [ignore]) +AT_CHECK([ovsdb-tool needs-conversion db schema2], [0], [yes +]) +AT_CLEANUP -- 1.7.1
Re: [ovs-dev] [db-backup 5/5] Avoid unneeded database compaction at startup, and improve backups.
I tested the xenserver version but not the Debian version. --- debian/openvswitch-switch.init | 13 - xenserver/etc_init.d_openvswitch | 15 --- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/debian/openvswitch-switch.init b/debian/openvswitch-switch.init index 60cc369..dd75e78 100755 --- a/debian/openvswitch-switch.init +++ b/debian/openvswitch-switch.init @@ -226,12 +226,15 @@ case $1 in if test ! -e $conf_file; then # Create configuration database. ovsdb-tool -vANY:console:emer create $conf_file $schema_file - else - # If schema version changed, then back up the old version. - old_ver=`ovsdb-tool db-version $conf_file` - if test X$old_ver != X$schema_ver; then - cp $conf_file $conf_file.backup$old_ver + elif test X`ovsdb-tool needs-conversion $conf_file $schema_file` != Xno; then + # Back up the old version. + suffix=`ovsdb-tool db-version $conf_file` + backup=$conf_file.backup$suffix + if test -e $backup; then + suffix=`ovsdb-tool db-cksum $conf_file | awk '{print $1}'` + backup=$conf_file.backup$suffix I think this is fine. However, we could alternatively always use the db-version and the checksum in the backup file name saving the need to check if it exists and having the added benefit of consistency. At any rate, looks good go ahead and merge when you're ready. Ethan ___ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev_openvswitch.org
Re: [ovs-dev] [db-backup 0/5] avoid unneeded db compaction and improve backups
On Tue, Feb 8, 2011 at 4:02 PM, Ethan Jackson et...@nicira.com wrote: I'll review this series unless someone else really wants to. But Justin is so *fond* of the database... -- I don't normally do acked-by's. I think it's my way of avoiding getting blamed when it all blows up. Andrew Morton ___ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev_openvswitch.org