diff options
author | Mark Michelson <mmichels@redhat.com> | 2018-02-26 14:04:02 -0600 |
---|---|---|
committer | Ben Pfaff <blp@ovn.org> | 2018-02-26 14:19:56 -0800 |
commit | 8519ea87d7b84166a02d8f3f25c91a2ff7d5fe57 (patch) | |
tree | c9f42eb8bdac4cbff8ed4d774646076190fb6018 /lib | |
parent | 2696bcb1205837b50cdf4f5402926efa8753f7f6 (diff) | |
download | openvswitch-8519ea87d7b84166a02d8f3f25c91a2ff7d5fe57.tar.gz |
Refer to database manpages in *ctl manpages
The ovn-nbctl, ovn-sbctl, and ovs-vsctl manpages are inconsistent in
their "Database Commands" section when it comes to referring to what
database tables exist. This commit amends this by making each *ctl
manpage reference the corresponding database manpage instead.
To aid in having a more handy list, the --help text of ovn-nbctl,
ovn-sbctl, and ovs-vsctl have been modified to list the available
tables. This is also referenced in the manpages for those applications.
Signed-off-by: Mark Michelson <mmichels@redhat.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/db-ctl-base.c | 69 | ||||
-rw-r--r-- | lib/db-ctl-base.h | 14 |
2 files changed, 72 insertions, 11 deletions
diff --git a/lib/db-ctl-base.c b/lib/db-ctl-base.c index 9fec6fa0d..ae7b6cde2 100644 --- a/lib/db-ctl-base.c +++ b/lib/db-ctl-base.c @@ -35,6 +35,7 @@ #include "ovsdb-idl-provider.h" #include "openvswitch/shash.h" #include "sset.h" +#include "svec.h" #include "string.h" #include "table.h" #include "util.h" @@ -61,6 +62,9 @@ static const struct cmd_show_table *cmd_show_tables; static void (*ctl_exit_func)(int status) = NULL; OVS_NO_RETURN static void ctl_exit(int status); +/* IDL class. */ +static const struct ovsdb_idl_class *idl_class; + /* Two arrays with 'n_classes' elements, which represent the tables in this * database and how the user can refer to their rows. */ static const struct ctl_table_class *ctl_classes; @@ -2132,15 +2136,15 @@ ctl_register_commands(const struct ctl_command_syntax *commands) /* Registers the 'db_ctl_commands' to 'all_commands'. */ void -ctl_init__(const struct ovsdb_idl_table_class *idl_classes_, +ctl_init__(const struct ovsdb_idl_class *idl_class_, const struct ctl_table_class *ctl_classes_, - size_t n_classes_, const struct cmd_show_table cmd_show_tables_[], void (*ctl_exit_func_)(int status)) { - idl_classes = idl_classes_; + idl_class = idl_class_; + idl_classes = idl_class_->tables; ctl_classes = ctl_classes_; - n_classes = n_classes_; + n_classes = idl_class->n_tables; ctl_exit_func = ctl_exit_func_; ctl_register_commands(db_ctl_commands); @@ -2170,6 +2174,63 @@ ctl_get_db_cmd_usage(void) Potentially unsafe database commands require --force option.\n"; } +const char * +ctl_list_db_tables_usage(void) +{ + static struct ds s = DS_EMPTY_INITIALIZER; + if (s.length) { + return ds_cstr(&s); + } + + ds_put_cstr(&s, "Database commands may reference a row in each table in the following ways:\n"); + for (int i = 0; i < n_classes; i++) { + struct svec options = SVEC_EMPTY_INITIALIZER; + + svec_add(&options, "by UUID"); + if (idl_classes[i].is_singleton) { + svec_add(&options, "as \".\""); + } + + for (int j = 0; j < ARRAY_SIZE(ctl_classes[i].row_ids); j++) { + const struct ctl_row_id *id = &ctl_classes[i].row_ids[j]; + if (!id->name_column) { + continue; + } + + struct ds o = DS_EMPTY_INITIALIZER; + if (id->uuid_column) { + ds_put_format(&o, "via \"%s\"", id->uuid_column->name); + const struct ovsdb_idl_table_class *referrer + = ovsdb_idl_table_class_from_column(idl_class, + id->uuid_column); + if (referrer != &idl_classes[i]) { + ds_put_format(&o, " of %s", referrer->name); + } + if (id->key) { + ds_put_format(&o, " with matching \"%s:%s\"", + id->name_column->name, id->key); + } else { + ds_put_format(&o, " with matching \"%s\"", id->name_column->name); + } + } else if (id->key) { + ds_put_format(&o, "by \"%s:%s\"", id->name_column->name, id->key); + } else { + ds_put_format(&o, "by \"%s\"", id->name_column->name); + } + svec_add_nocopy(&options, ds_steal_cstr(&o)); + } + + ds_put_format(&s, " %s:", idl_classes[i].name); + for (int j = 0; j < options.n; j++) { + ds_put_format(&s, "\n %s", options.names[j]); + } + ds_put_char(&s, '\n'); + svec_destroy(&options); + } + + return ds_cstr(&s); +} + /* Initializes 'ctx' from 'command'. */ void ctl_context_init_command(struct ctl_context *ctx, diff --git a/lib/db-ctl-base.h b/lib/db-ctl-base.h index 81f0d0b27..a2f91abfb 100644 --- a/lib/db-ctl-base.h +++ b/lib/db-ctl-base.h @@ -51,13 +51,11 @@ struct cmd_show_table; /* ctl_init() figures out the number of tables on its own and flags an error if * 'ctl_classes' was defined with the wrong number of elements. */ -#define ctl_init(idl_classes, ctl_classes, cmd_show_table, ctl_exit_func) \ - (BUILD_ASSERT(ARRAY_SIZE(idl_classes) == ARRAY_SIZE(ctl_classes)), \ - ctl_init__(idl_classes, ctl_classes, ARRAY_SIZE(idl_classes), \ - cmd_show_table, ctl_exit_func)) -void ctl_init__(const struct ovsdb_idl_table_class *idl_classes, - const struct ctl_table_class *ctl_classes, - size_t n_classes, +#define ctl_init(idl_class, table_classes, ctl_classes, cmd_show_table, \ + ctl_exit_func) \ + (BUILD_ASSERT(ARRAY_SIZE(table_classes) == ARRAY_SIZE(ctl_classes)), \ + ctl_init__(idl_class, ctl_classes, cmd_show_table, ctl_exit_func)) +void ctl_init__(const struct ovsdb_idl_class *, const struct ctl_table_class *, const struct cmd_show_table *cmd_show_tables, void (*ctl_exit_func)(int status)); char *ctl_default_db(void); @@ -159,6 +157,8 @@ struct ctl_command { bool ctl_might_write_to_db(char **argv); const char *ctl_get_db_cmd_usage(void); + +const char *ctl_list_db_tables_usage(void); void ctl_print_commands(void); void ctl_print_options(const struct option *); void ctl_add_cmd_options(struct option **, size_t *n_options_p, |