X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=utilities%2Fovs-vsctl.c;h=48ae56be895c84bb699f28b10aa211b1abcbdfcc;hb=8084c0119cc9b6125697a316e03256d0d4555749;hp=18bf63b7210bf31e51b577f7732b794f4f8a657b;hpb=9591fefeea4b475ee0d1387486a410bbb592b050;p=sliver-openvswitch.git diff --git a/utilities/ovs-vsctl.c b/utilities/ovs-vsctl.c index 18bf63b72..48ae56be8 100644 --- a/utilities/ovs-vsctl.c +++ b/utilities/ovs-vsctl.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2010, 2011 Nicira Networks. + * Copyright (c) 2009, 2010, 2011, 2012 Nicira Networks. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,6 +26,7 @@ #include #include #include +#include #include "command-line.h" #include "compiler.h" @@ -36,11 +37,15 @@ #include "ovsdb-idl.h" #include "poll-loop.h" #include "process.h" +#include "stream.h" #include "stream-ssl.h" +#include "sset.h" #include "svec.h" #include "vswitchd/vswitch-idl.h" +#include "table.h" #include "timeval.h" #include "util.h" +#include "vconn.h" #include "vlog.h" VLOG_DEFINE_THIS_MODULE(vsctl); @@ -61,7 +66,7 @@ struct vsctl_command_syntax { void (*prerequisites)(struct vsctl_context *ctx); /* Does the actual work of the command and puts the command's output, if - * any, in ctx->output. + * any, in ctx->output or ctx->table. * * Alternatively, if some prerequisite of the command is not met and the * caller should wait for something to change and then retry, it may set @@ -90,6 +95,7 @@ struct vsctl_command { /* Data modified by commands. */ struct ds output; + struct table *table; }; /* --db: The database server to contact. */ @@ -107,6 +113,9 @@ static bool wait_for_reload = true; /* --timeout: Time to wait for a connection to 'db'. */ static int timeout; +/* Format for table output. */ +static struct table_style table_style = TABLE_STYLE_DEFAULT; + /* All supported commands. */ static const struct vsctl_command_syntax all_commands[]; @@ -129,19 +138,25 @@ static void parse_command(int argc, char *argv[], struct vsctl_command *); static const struct vsctl_command_syntax *find_command(const char *name); static void run_prerequisites(struct vsctl_command[], size_t n_commands, struct ovsdb_idl *); -static void do_vsctl(const char *args, - struct vsctl_command *, size_t n_commands, - struct ovsdb_idl *); +static enum ovsdb_idl_txn_status do_vsctl(const char *args, + struct vsctl_command *, size_t n, + struct ovsdb_idl *); static const struct vsctl_table_class *get_table(const char *table_name); static void set_column(const struct vsctl_table_class *, const struct ovsdb_idl_row *, const char *arg, struct ovsdb_symbol_table *); +static bool is_condition_satisfied(const struct vsctl_table_class *, + const struct ovsdb_idl_row *, + const char *arg, + struct ovsdb_symbol_table *); + int main(int argc, char *argv[]) { extern struct vlog_module VLM_reconnect; + enum ovsdb_idl_txn_status status; struct ovsdb_idl *idl; struct vsctl_command *commands; size_t n_commands; @@ -170,13 +185,16 @@ main(int argc, char *argv[]) run_prerequisites(commands, n_commands, idl); /* Now execute the commands. */ + status = TXN_AGAIN_WAIT; for (;;) { - if (ovsdb_idl_run(idl)) { - do_vsctl(args, commands, n_commands, idl); + if (ovsdb_idl_run(idl) || status == TXN_AGAIN_NOW) { + status = do_vsctl(args, commands, n_commands, idl); } - ovsdb_idl_wait(idl); - poll_block(); + if (status != TXN_AGAIN_NOW) { + ovsdb_idl_wait(idl); + poll_block(); + } } } @@ -190,23 +208,23 @@ parse_options(int argc, char *argv[]) OPT_NO_WAIT, OPT_DRY_RUN, OPT_PEER_CA_CERT, - VLOG_OPTION_ENUMS + VLOG_OPTION_ENUMS, + TABLE_OPTION_ENUMS }; static struct option long_options[] = { - {"db", required_argument, 0, OPT_DB}, - {"no-syslog", no_argument, 0, OPT_NO_SYSLOG}, - {"no-wait", no_argument, 0, OPT_NO_WAIT}, - {"dry-run", no_argument, 0, OPT_DRY_RUN}, - {"oneline", no_argument, 0, OPT_ONELINE}, - {"timeout", required_argument, 0, 't'}, - {"help", no_argument, 0, 'h'}, - {"version", no_argument, 0, 'V'}, + {"db", required_argument, NULL, OPT_DB}, + {"no-syslog", no_argument, NULL, OPT_NO_SYSLOG}, + {"no-wait", no_argument, NULL, OPT_NO_WAIT}, + {"dry-run", no_argument, NULL, OPT_DRY_RUN}, + {"oneline", no_argument, NULL, OPT_ONELINE}, + {"timeout", required_argument, NULL, 't'}, + {"help", no_argument, NULL, 'h'}, + {"version", no_argument, NULL, 'V'}, VLOG_LONG_OPTIONS, -#ifdef HAVE_OPENSSL - STREAM_SSL_LONG_OPTIONS - {"peer-ca-cert", required_argument, 0, OPT_PEER_CA_CERT}, -#endif - {0, 0, 0, 0}, + TABLE_LONG_OPTIONS, + STREAM_SSL_LONG_OPTIONS, + {"peer-ca-cert", required_argument, NULL, OPT_PEER_CA_CERT}, + {NULL, 0, NULL, 0}, }; char *tmp, *short_options; @@ -214,6 +232,8 @@ parse_options(int argc, char *argv[]) short_options = xasprintf("+%s", tmp); free(tmp); + table_style.format = TF_LIST; + for (;;) { int c; @@ -247,7 +267,7 @@ parse_options(int argc, char *argv[]) usage(); case 'V': - OVS_PRINT_VERSION(0, 0); + ovs_print_version(0, 0); exit(EXIT_SUCCESS); case 't': @@ -259,14 +279,13 @@ parse_options(int argc, char *argv[]) break; VLOG_OPTION_HANDLERS + TABLE_OPTION_HANDLERS(&table_style) -#ifdef HAVE_OPENSSL STREAM_SSL_OPTION_HANDLERS case OPT_PEER_CA_CERT: stream_ssl_set_peer_ca_cert_file(optarg); break; -#endif case '?': exit(EXIT_FAILURE); @@ -430,7 +449,7 @@ vsctl_fatal(const char *format, ...) message = xvasprintf(format, args); va_end(args); - vlog_set_levels(&VLM_vsctl, VLF_CONSOLE, VLL_EMER); + vlog_set_levels(&VLM_vsctl, VLF_CONSOLE, VLL_OFF); VLOG_ERR("%s", message); ovs_error(0, "%s", message); vsctl_exit(EXIT_FAILURE); @@ -460,6 +479,11 @@ usage(void) %s: ovs-vswitchd management utility\n\ usage: %s [OPTIONS] COMMAND [ARG...]\n\ \n\ +Open vSwitch commands:\n\ + init initialize database, if not yet initialized\n\ + show print overview of database contents\n\ + emer-reset reset configuration to clean state\n\ +\n\ Bridge commands:\n\ add-br BRIDGE create a new bridge named BRIDGE\n\ add-br BRIDGE PARENT VLAN create new fake BRIDGE in PARENT on VLAN\n\ @@ -473,30 +497,29 @@ Bridge commands:\n\ br-get-external-id BRIDGE KEY print value of KEY on BRIDGE\n\ br-get-external-id BRIDGE list key-value pairs on BRIDGE\n\ \n\ -Port commands:\n\ +Port commands (a bond is considered to be a single port):\n\ list-ports BRIDGE print the names of all the ports on BRIDGE\n\ add-port BRIDGE PORT add network device PORT to BRIDGE\n\ add-bond BRIDGE PORT IFACE... add bonded port PORT in BRIDGE from IFACES\n\ del-port [BRIDGE] PORT delete PORT (which may be bonded) from BRIDGE\n\ port-to-br PORT print name of bridge that contains PORT\n\ -A bond is considered to be a single port.\n\ \n\ Interface commands (a bond consists of multiple interfaces):\n\ list-ifaces BRIDGE print the names of all interfaces on BRIDGE\n\ iface-to-br IFACE print name of bridge that contains IFACE\n\ \n\ Controller commands:\n\ - get-controller BRIDGE print the controller for BRIDGE\n\ - del-controller BRIDGE delete the controller for BRIDGE\n\ - set-controller BRIDGE TARGET set the controller for BRIDGE to TARGET\n\ + get-controller BRIDGE print the controllers for BRIDGE\n\ + del-controller BRIDGE delete the controllers for BRIDGE\n\ + set-controller BRIDGE TARGET... set the controllers for BRIDGE\n\ get-fail-mode BRIDGE print the fail-mode for BRIDGE\n\ del-fail-mode BRIDGE delete the fail-mode for BRIDGE\n\ set-fail-mode BRIDGE MODE set the fail-mode for BRIDGE to MODE\n\ \n\ Manager commands:\n\ - get-manager print all manager(s)\n\ - del-manager delete all manager(s)\n\ - set-manager TARGET... set the list of manager(s) to TARGET(s)\n\ + get-manager print the managers\n\ + del-manager delete the managers\n\ + set-manager TARGET... set the list of managers to TARGET...\n\ \n\ SSL commands:\n\ get-ssl print the SSL configuration\n\ @@ -508,6 +531,7 @@ Switch commands:\n\ \n\ Database commands:\n\ list TBL [REC] list RECord (or all records) in TBL\n\ + find TBL CONDITION... list records satisfying CONDITION in TBL\n\ get TBL REC COL[:KEY] print values of COLumns in RECord in TBL\n\ set TBL REC COL[:KEY]=VALUE set COLumn values in RECord in TBL\n\ add TBL REC COL [KEY=]VALUE add (KEY=)VALUE to COLumn in RECord in TBL\n\ @@ -521,9 +545,15 @@ Potentially unsafe database commands require --force option.\n\ Options:\n\ --db=DATABASE connect to DATABASE\n\ (default: %s)\n\ + --no-wait do not wait for ovs-vswitchd to reconfigure\n\ + -t, --timeout=SECS wait at most SECS seconds for ovs-vswitchd\n\ + --dry-run do not commit changes to database\n\ --oneline print exactly one line of output per command\n", program_name, program_name, default_db()); vlog_usage(); + printf("\ + --no-syslog equivalent to --verbose=vsctl:syslog:warn\n"); + stream_usage("database", true, true, false); printf("\n\ Other options:\n\ -h, --help display this help message\n\ @@ -564,6 +594,7 @@ struct vsctl_context { /* Modifiable state. */ struct ds output; + struct table *table; struct ovsdb_idl *idl; struct ovsdb_idl_txn *txn; struct ovsdb_symbol_table *symtab; @@ -730,7 +761,7 @@ static void get_info(struct vsctl_context *ctx, struct vsctl_info *info) { const struct ovsrec_open_vswitch *ovs = ctx->ovs; - struct shash bridges, ports; + struct sset bridges, ports; size_t i; info->ctx = ctx; @@ -738,14 +769,14 @@ get_info(struct vsctl_context *ctx, struct vsctl_info *info) shash_init(&info->ports); shash_init(&info->ifaces); - shash_init(&bridges); - shash_init(&ports); + sset_init(&bridges); + sset_init(&ports); for (i = 0; i < ovs->n_bridges; i++) { struct ovsrec_bridge *br_cfg = ovs->bridges[i]; struct vsctl_bridge *br; size_t j; - if (!shash_add_once(&bridges, br_cfg->name, NULL)) { + if (!sset_add(&bridges, br_cfg->name)) { VLOG_WARN("%s: database contains duplicate bridge name", br_cfg->name); continue; @@ -758,29 +789,27 @@ get_info(struct vsctl_context *ctx, struct vsctl_info *info) for (j = 0; j < br_cfg->n_ports; j++) { struct ovsrec_port *port_cfg = br_cfg->ports[j]; - if (!shash_add_once(&ports, port_cfg->name, NULL)) { - VLOG_WARN("%s: database contains duplicate port name", - port_cfg->name); + if (!sset_add(&ports, port_cfg->name)) { + /* Duplicate port name. (We will warn about that later.) */ continue; } if (port_is_fake_bridge(port_cfg) - && shash_add_once(&bridges, port_cfg->name, NULL)) { + && sset_add(&bridges, port_cfg->name)) { add_bridge(info, NULL, port_cfg->name, br, *port_cfg->tag); } } } - shash_destroy(&bridges); - shash_destroy(&ports); + sset_destroy(&bridges); + sset_destroy(&ports); - shash_init(&bridges); - shash_init(&ports); + sset_init(&bridges); for (i = 0; i < ovs->n_bridges; i++) { struct ovsrec_bridge *br_cfg = ovs->bridges[i]; struct vsctl_bridge *br; size_t j; - if (!shash_add_once(&bridges, br_cfg->name, NULL)) { + if (!sset_add(&bridges, br_cfg->name)) { continue; } br = shash_find_data(&info->bridges, br_cfg->name); @@ -789,12 +818,23 @@ get_info(struct vsctl_context *ctx, struct vsctl_info *info) struct vsctl_port *port; size_t k; - if (!shash_add_once(&ports, port_cfg->name, NULL)) { + port = shash_find_data(&info->ports, port_cfg->name); + if (port) { + if (port_cfg == port->port_cfg) { + VLOG_WARN("%s: port is in multiple bridges (%s and %s)", + port_cfg->name, br->name, port->bridge->name); + } else { + /* Log as an error because this violates the database's + * uniqueness constraints, so the database server shouldn't + * have allowed it. */ + VLOG_ERR("%s: database contains duplicate port name", + port_cfg->name); + } continue; } if (port_is_fake_bridge(port_cfg) - && !shash_add_once(&bridges, port_cfg->name, NULL)) { + && !sset_add(&bridges, port_cfg->name)) { continue; } @@ -815,9 +855,21 @@ get_info(struct vsctl_context *ctx, struct vsctl_info *info) struct ovsrec_interface *iface_cfg = port_cfg->interfaces[k]; struct vsctl_iface *iface; - if (shash_find(&info->ifaces, iface_cfg->name)) { - VLOG_WARN("%s: database contains duplicate interface name", - iface_cfg->name); + iface = shash_find_data(&info->ifaces, iface_cfg->name); + if (iface) { + if (iface_cfg == iface->iface_cfg) { + VLOG_WARN("%s: interface is in multiple ports " + "(%s and %s)", + iface_cfg->name, + iface->port->port_cfg->name, + port->port_cfg->name); + } else { + /* Log as an error because this violates the database's + * uniqueness constraints, so the database server + * shouldn't have allowed it. */ + VLOG_ERR("%s: database contains duplicate interface " + "name", iface_cfg->name); + } continue; } @@ -828,8 +880,7 @@ get_info(struct vsctl_context *ctx, struct vsctl_info *info) } } } - shash_destroy(&bridges); - shash_destroy(&ports); + sset_destroy(&bridges); } static void @@ -979,10 +1030,189 @@ cmd_init(struct vsctl_context *ctx OVS_UNUSED) { } +struct cmd_show_table { + const struct ovsdb_idl_table_class *table; + const struct ovsdb_idl_column *name_column; + const struct ovsdb_idl_column *columns[3]; + bool recurse; +}; + +static struct cmd_show_table cmd_show_tables[] = { + {&ovsrec_table_open_vswitch, + NULL, + {&ovsrec_open_vswitch_col_manager_options, + &ovsrec_open_vswitch_col_bridges, + &ovsrec_open_vswitch_col_ovs_version}, + false}, + + {&ovsrec_table_bridge, + &ovsrec_bridge_col_name, + {&ovsrec_bridge_col_controller, + &ovsrec_bridge_col_fail_mode, + &ovsrec_bridge_col_ports}, + false}, + + {&ovsrec_table_port, + &ovsrec_port_col_name, + {&ovsrec_port_col_tag, + &ovsrec_port_col_trunks, + &ovsrec_port_col_interfaces}, + false}, + + {&ovsrec_table_interface, + &ovsrec_interface_col_name, + {&ovsrec_interface_col_type, + &ovsrec_interface_col_options, + NULL}, + false}, + + {&ovsrec_table_controller, + &ovsrec_controller_col_target, + {&ovsrec_controller_col_is_connected, + NULL, + NULL}, + false}, + + {&ovsrec_table_manager, + &ovsrec_manager_col_target, + {&ovsrec_manager_col_is_connected, + NULL, + NULL}, + false}, +}; + +static void +pre_cmd_show(struct vsctl_context *ctx) +{ + struct cmd_show_table *show; + + for (show = cmd_show_tables; + show < &cmd_show_tables[ARRAY_SIZE(cmd_show_tables)]; + show++) { + size_t i; + + ovsdb_idl_add_table(ctx->idl, show->table); + if (show->name_column) { + ovsdb_idl_add_column(ctx->idl, show->name_column); + } + for (i = 0; i < ARRAY_SIZE(show->columns); i++) { + const struct ovsdb_idl_column *column = show->columns[i]; + if (column) { + ovsdb_idl_add_column(ctx->idl, column); + } + } + } +} + +static struct cmd_show_table * +cmd_show_find_table_by_row(const struct ovsdb_idl_row *row) +{ + struct cmd_show_table *show; + + for (show = cmd_show_tables; + show < &cmd_show_tables[ARRAY_SIZE(cmd_show_tables)]; + show++) { + if (show->table == row->table->class) { + return show; + } + } + return NULL; +} + +static struct cmd_show_table * +cmd_show_find_table_by_name(const char *name) +{ + struct cmd_show_table *show; + + for (show = cmd_show_tables; + show < &cmd_show_tables[ARRAY_SIZE(cmd_show_tables)]; + show++) { + if (!strcmp(show->table->name, name)) { + return show; + } + } + return NULL; +} + +static void +cmd_show_row(struct vsctl_context *ctx, const struct ovsdb_idl_row *row, + int level) +{ + struct cmd_show_table *show = cmd_show_find_table_by_row(row); + size_t i; + + ds_put_char_multiple(&ctx->output, ' ', level * 4); + if (show && show->name_column) { + const struct ovsdb_datum *datum; + + ds_put_format(&ctx->output, "%s ", show->table->name); + datum = ovsdb_idl_read(row, show->name_column); + ovsdb_datum_to_string(datum, &show->name_column->type, &ctx->output); + } else { + ds_put_format(&ctx->output, UUID_FMT, UUID_ARGS(&row->uuid)); + } + ds_put_char(&ctx->output, '\n'); + + if (!show || show->recurse) { + return; + } + + show->recurse = true; + for (i = 0; i < ARRAY_SIZE(show->columns); i++) { + const struct ovsdb_idl_column *column = show->columns[i]; + const struct ovsdb_datum *datum; + + if (!column) { + break; + } + + datum = ovsdb_idl_read(row, column); + if (column->type.key.type == OVSDB_TYPE_UUID && + column->type.key.u.uuid.refTableName) { + struct cmd_show_table *ref_show; + size_t j; + + ref_show = cmd_show_find_table_by_name( + column->type.key.u.uuid.refTableName); + if (ref_show) { + for (j = 0; j < datum->n; j++) { + const struct ovsdb_idl_row *ref_row; + + ref_row = ovsdb_idl_get_row_for_uuid(ctx->idl, + ref_show->table, + &datum->keys[j].uuid); + if (ref_row) { + cmd_show_row(ctx, ref_row, level + 1); + } + } + continue; + } + } + + if (!ovsdb_datum_is_default(datum, &column->type)) { + ds_put_char_multiple(&ctx->output, ' ', (level + 1) * 4); + ds_put_format(&ctx->output, "%s: ", column->name); + ovsdb_datum_to_string(datum, &column->type, &ctx->output); + ds_put_char(&ctx->output, '\n'); + } + } + show->recurse = false; +} + +static void +cmd_show(struct vsctl_context *ctx) +{ + const struct ovsdb_idl_row *row; + + for (row = ovsdb_idl_first_row(ctx->idl, cmd_show_tables[0].table); + row; row = ovsdb_idl_next_row(row)) { + cmd_show_row(ctx, row, 0); + } +} + static void pre_cmd_emer_reset(struct vsctl_context *ctx) { - ovsdb_idl_add_column(ctx->idl, &ovsrec_open_vswitch_col_managers); ovsdb_idl_add_column(ctx->idl, &ovsrec_open_vswitch_col_manager_options); ovsdb_idl_add_column(ctx->idl, &ovsrec_open_vswitch_col_ssl); @@ -1017,7 +1247,6 @@ cmd_emer_reset(struct vsctl_context *ctx) const struct ovsrec_sflow *sflow, *next_sflow; /* Reset the Open_vSwitch table. */ - ovsrec_open_vswitch_set_managers(ctx->ovs, NULL, 0); ovsrec_open_vswitch_set_manager_options(ctx->ovs, NULL, 0); ovsrec_open_vswitch_set_ssl(ctx->ovs, NULL); @@ -1088,7 +1317,7 @@ cmd_emer_reset(struct vsctl_context *ctx) static void cmd_add_br(struct vsctl_context *ctx) { - bool may_exist = shash_find(&ctx->options, "--may-exist") != 0; + bool may_exist = shash_find(&ctx->options, "--may-exist") != NULL; const char *br_name, *parent_name; struct vsctl_info info; int vlan; @@ -1378,7 +1607,7 @@ get_external_id(char **keys, char **values, size_t n, if (!key && !strncmp(keys[i], prefix, prefix_len)) { svec_add_nocopy(&svec, xasprintf("%s=%s", keys[i] + prefix_len, values[i])); - } else if (key_matches(keys[i], prefix, prefix_len, key)) { + } else if (key && key_matches(keys[i], prefix, prefix_len, key)) { svec_add(&svec, values[i]); break; } @@ -1540,7 +1769,7 @@ add_port(struct vsctl_context *ctx, static void cmd_add_port(struct vsctl_context *ctx) { - bool may_exist = shash_find(&ctx->options, "--may-exist") != 0; + bool may_exist = shash_find(&ctx->options, "--may-exist") != NULL; add_port(ctx, ctx->argv[1], ctx->argv[2], may_exist, false, &ctx->argv[2], 1, &ctx->argv[3], ctx->argc - 3); @@ -1549,7 +1778,7 @@ cmd_add_port(struct vsctl_context *ctx) static void cmd_add_bond(struct vsctl_context *ctx) { - bool may_exist = shash_find(&ctx->options, "--may-exist") != 0; + bool may_exist = shash_find(&ctx->options, "--may-exist") != NULL; bool fake_iface = shash_find(&ctx->options, "--fake-iface"); int n_ifaces; int i; @@ -1766,6 +1995,7 @@ cmd_del_controller(struct vsctl_context *ctx) struct vsctl_bridge *br; get_info(ctx, &info); + br = find_real_bridge(&info, ctx->argv[1], true); verify_controllers(br->br_cfg); @@ -1785,6 +2015,9 @@ insert_controllers(struct ovsdb_idl_txn *txn, char *targets[], size_t n) controllers = xmalloc(n * sizeof *controllers); for (i = 0; i < n; i++) { + if (vconn_verify_name(targets[i]) && pvconn_verify_name(targets[i])) { + VLOG_WARN("target type \"%s\" is possibly erroneous", targets[i]); + } controllers[i] = ovsrec_controller_insert(txn); ovsrec_controller_set_target(controllers[i], targets[i]); } @@ -1871,7 +2104,6 @@ verify_managers(const struct ovsrec_open_vswitch *ovs) { size_t i; - ovsrec_open_vswitch_verify_managers(ovs); ovsrec_open_vswitch_verify_manager_options(ovs); for (i = 0; i < ovs->n_manager_options; ++i) { @@ -1884,7 +2116,6 @@ verify_managers(const struct ovsrec_open_vswitch *ovs) static void pre_manager(struct vsctl_context *ctx) { - ovsdb_idl_add_column(ctx->idl, &ovsrec_open_vswitch_col_managers); ovsdb_idl_add_column(ctx->idl, &ovsrec_open_vswitch_col_manager_options); ovsdb_idl_add_column(ctx->idl, &ovsrec_manager_col_target); } @@ -1901,12 +2132,6 @@ cmd_get_manager(struct vsctl_context *ctx) /* Print the targets in sorted order for reproducibility. */ svec_init(&targets); - /* First, add all targets found in deprecated 'managers' column. */ - for (i = 0; i < ovs->n_managers; i++) { - svec_add(&targets, ovs->managers[i]); - } - - /* Second, add all targets pointed to by 'manager_options' column. */ for (i = 0; i < ovs->n_manager_options; i++) { svec_add(&targets, ovs->manager_options[i]->target); } @@ -1924,9 +2149,6 @@ delete_managers(const struct vsctl_context *ctx) const struct ovsrec_open_vswitch *ovs = ctx->ovs; size_t i; - /* Delete manager targets in deprecated 'managers' column. */ - ovsrec_open_vswitch_set_managers(ovs, NULL, 0); - /* Delete Manager rows pointed to by 'manager_options' column. */ for (i = 0; i < ovs->n_manager_options; i++) { ovsrec_manager_delete(ovs->manager_options[i]); @@ -1951,12 +2173,12 @@ insert_managers(struct vsctl_context *ctx, char *targets[], size_t n) struct ovsrec_manager **managers; size_t i; - /* Store in deprecated 'manager' column. */ - ovsrec_open_vswitch_set_managers(ctx->ovs, targets, n); - /* Insert each manager in a new row in Manager table. */ managers = xmalloc(n * sizeof *managers); for (i = 0; i < n; i++) { + if (stream_verify_name(targets[i]) && pstream_verify_name(targets[i])) { + VLOG_WARN("target type \"%s\" is possibly erroneous", targets[i]); + } managers[i] = ovsrec_manager_insert(ctx->txn); ovsrec_manager_set_target(managers[i], targets[i]); } @@ -2105,16 +2327,6 @@ static const struct vsctl_table_class tables[] = { {{&ovsrec_table_port, &ovsrec_port_col_name, &ovsrec_port_col_qos}, {NULL, NULL, NULL}}}, - {&ovsrec_table_monitor, - {{&ovsrec_table_interface, - &ovsrec_interface_col_name, - &ovsrec_interface_col_monitor}, - {NULL, NULL, NULL}}}, - - {&ovsrec_table_maintenance_point, - {{NULL, NULL, NULL}, - {NULL, NULL, NULL}}}, - {&ovsrec_table_queue, {{NULL, NULL, NULL}, {NULL, NULL, NULL}}}, @@ -2128,6 +2340,10 @@ static const struct vsctl_table_class tables[] = { &ovsrec_bridge_col_sflow}, {NULL, NULL, NULL}}}, + {&ovsrec_table_flow_table, + {{&ovsrec_table_flow_table, &ovsrec_flow_table_col_name, NULL}, + {NULL, NULL, NULL}}}, + {NULL, {{NULL, NULL, NULL}, {NULL, NULL, NULL}}} }; @@ -2340,7 +2556,7 @@ get_column(const struct vsctl_table_class *table, const char *column_name, } } -static struct uuid * +static struct ovsdb_symbol * create_symbol(struct ovsdb_symbol_table *symtab, const char *id, bool *newp) { struct ovsdb_symbol *symbol; @@ -2354,12 +2570,12 @@ create_symbol(struct ovsdb_symbol_table *symtab, const char *id, bool *newp) } symbol = ovsdb_symbol_table_insert(symtab, id); - if (symbol->used) { + if (symbol->created) { vsctl_fatal("row id \"%s\" may only be specified on one --id option", id); } - symbol->used = true; - return &symbol->uuid; + symbol->created = true; + return symbol; } static void @@ -2397,23 +2613,19 @@ missing_operator_error(const char *arg, const char **allowed_operators, /* Breaks 'arg' apart into a number of fields in the following order: * - * - If 'columnp' is nonnull, the name of a column in 'table'. The column - * is stored into '*columnp'. The column name may be abbreviated. + * - The name of a column in 'table', stored into '*columnp'. The column + * name may be abbreviated. * - * - If 'keyp' is nonnull, optionally a key string. (If both 'columnp' - * and 'keyp' are nonnull, then the column and key names are expected to - * be separated by ':'). The key is stored as a malloc()'d string into - * '*keyp', or NULL if no key is present in 'arg'. + * - Optionally ':' followed by a key string. The key is stored as a + * malloc()'d string into '*keyp', or NULL if no key is present in + * 'arg'. * * - If 'valuep' is nonnull, an operator followed by a value string. The * allowed operators are the 'n_allowed' string in 'allowed_operators', * or just "=" if 'n_allowed' is 0. If 'operatorp' is nonnull, then the - * operator is stored into '*operatorp' (one of the pointers from - * 'allowed_operators' is stored; nothing is malloc()'d). The value is - * stored as a malloc()'d string into '*valuep', or NULL if no value is - * present in 'arg'. - * - * At least 'columnp' or 'keyp' must be nonnull. + * index of the operator within 'allowed_operators' is stored into + * '*operatorp'. The value is stored as a malloc()'d string into + * '*valuep', or NULL if no value is present in 'arg'. * * On success, returns NULL. On failure, returned a malloc()'d string error * message and stores NULL into all of the nonnull output arguments. */ @@ -2421,63 +2633,50 @@ static char * WARN_UNUSED_RESULT parse_column_key_value(const char *arg, const struct vsctl_table_class *table, const struct ovsdb_idl_column **columnp, char **keyp, - const char **operatorp, + int *operatorp, const char **allowed_operators, size_t n_allowed, char **valuep) { const char *p = arg; + char *column_name; char *error; - assert(columnp || keyp); assert(!(operatorp && !valuep)); - if (keyp) { - *keyp = NULL; - } + *keyp = NULL; if (valuep) { *valuep = NULL; } /* Parse column name. */ - if (columnp) { - char *column_name; - - error = ovsdb_token_parse(&p, &column_name); - if (error) { - goto error; - } - if (column_name[0] == '\0') { - free(column_name); - error = xasprintf("%s: missing column name", arg); - goto error; - } - error = get_column(table, column_name, columnp); + error = ovsdb_token_parse(&p, &column_name); + if (error) { + goto error; + } + if (column_name[0] == '\0') { free(column_name); - if (error) { - goto error; - } + error = xasprintf("%s: missing column name", arg); + goto error; + } + error = get_column(table, column_name, columnp); + free(column_name); + if (error) { + goto error; } /* Parse key string. */ - if (*p == ':' || !columnp) { - if (columnp) { - p++; - } else if (!keyp) { - error = xasprintf("%s: key not accepted here", arg); - goto error; - } + if (*p == ':') { + p++; error = ovsdb_token_parse(&p, keyp); if (error) { goto error; } - } else if (keyp) { - *keyp = NULL; } /* Parse value string. */ if (valuep) { - const char *best; size_t best_len; size_t i; + int best; if (!allowed_operators) { static const char *equals = "="; @@ -2485,7 +2684,7 @@ parse_column_key_value(const char *arg, n_allowed = 1; } - best = NULL; + best = -1; best_len = 0; for (i = 0; i < n_allowed; i++) { const char *op = allowed_operators[i]; @@ -2493,10 +2692,10 @@ parse_column_key_value(const char *arg, if (op_len > best_len && !strncmp(op, p, op_len) && p[op_len]) { best_len = op_len; - best = op; + best = i; } } - if (!best) { + if (best < 0) { error = missing_operator_error(arg, allowed_operators, n_allowed); goto error; } @@ -2506,9 +2705,6 @@ parse_column_key_value(const char *arg, } *valuep = xstrdup(p + best_len); } else { - if (valuep) { - *valuep = NULL; - } if (*p != '\0') { error = xasprintf("%s: trailing garbage \"%s\" in argument", arg, p); @@ -2518,18 +2714,14 @@ parse_column_key_value(const char *arg, return NULL; error: - if (columnp) { - *columnp = NULL; - } - if (keyp) { - free(*keyp); - *keyp = NULL; - } + *columnp = NULL; + free(*keyp); + *keyp = NULL; if (valuep) { free(*valuep); *valuep = NULL; if (operatorp) { - *operatorp = NULL; + *operatorp = -1; } } return error; @@ -2557,10 +2749,20 @@ pre_parse_column_key_value(struct vsctl_context *ctx, static void pre_cmd_get(struct vsctl_context *ctx) { + const char *id = shash_find_data(&ctx->options, "--id"); const char *table_name = ctx->argv[1]; const struct vsctl_table_class *table; int i; + /* Using "get" without --id or a column name could possibly make sense. + * Maybe, for example, a ovs-vsctl run wants to assert that a row exists. + * But it is unlikely that an interactive user would want to do that, so + * issue a warning if we're running on a terminal. */ + if (!id && ctx->argc <= 3 && isatty(STDOUT_FILENO)) { + VLOG_WARN("\"get\" command without row arguments or \"--id\" is " + "possibly erroneous"); + } + table = pre_get_table(ctx, table_name); for (i = 3; i < ctx->argc; i++) { if (!strcasecmp(ctx->argv[i], "_uuid") @@ -2587,13 +2789,19 @@ cmd_get(struct vsctl_context *ctx) table = get_table(table_name); row = must_get_row(ctx, table, record_id); if (id) { + struct ovsdb_symbol *symbol; bool new; - *create_symbol(ctx->symtab, id, &new) = row->uuid; + symbol = create_symbol(ctx->symtab, id, &new); if (!new) { vsctl_fatal("row id \"%s\" specified on \"get\" command was used " "before it was defined", id); } + symbol->uuid = row->uuid; + + /* This symbol refers to a row that already exists, so disable warnings + * about it being unreferenced. */ + symbol->strong_ref = true; } for (i = 3; i < ctx->argc; i++) { const struct ovsdb_idl_column *column; @@ -2731,24 +2939,54 @@ pre_cmd_list(struct vsctl_context *ctx) pre_list_columns(ctx, table, column_names); } +static struct table * +list_make_table(const struct ovsdb_idl_column **columns, size_t n_columns) +{ + struct table *out; + size_t i; + + out = xmalloc(sizeof *out); + table_init(out); + + for (i = 0; i < n_columns; i++) { + const struct ovsdb_idl_column *column = columns[i]; + const char *column_name = column ? column->name : "_uuid"; + + table_add_column(out, "%s", column_name); + } + + return out; +} + static void list_record(const struct ovsdb_idl_row *row, const struct ovsdb_idl_column **columns, size_t n_columns, - struct ds *out) + struct table *out) { size_t i; + table_add_row(out); for (i = 0; i < n_columns; i++) { const struct ovsdb_idl_column *column = columns[i]; + struct cell *cell = table_add_cell(out); if (!column) { - ds_put_format(out, "%-20s: "UUID_FMT"\n", "_uuid", - UUID_ARGS(&row->uuid)); + struct ovsdb_datum datum; + union ovsdb_atom atom; + + atom.uuid = row->uuid; + + datum.keys = &atom; + datum.values = NULL; + datum.n = 1; + + cell->json = ovsdb_datum_to_json(&datum, &ovsdb_type_uuid); + cell->type = &ovsdb_type_uuid; } else { const struct ovsdb_datum *datum = ovsdb_idl_read(row, column); - ds_put_format(out, "%-20s: ", column->name); - ovsdb_datum_to_string(datum, &column->type, out); - ds_put_char(out, '\n'); + + cell->json = ovsdb_datum_to_json(datum, &column->type); + cell->type = &column->type; } } } @@ -2760,36 +2998,75 @@ cmd_list(struct vsctl_context *ctx) const struct ovsdb_idl_column **columns; const char *table_name = ctx->argv[1]; const struct vsctl_table_class *table; - struct ds *out = &ctx->output; + struct table *out; size_t n_columns; int i; table = get_table(table_name); parse_column_names(column_names, table, &columns, &n_columns); + out = ctx->table = list_make_table(columns, n_columns); if (ctx->argc > 2) { for (i = 2; i < ctx->argc; i++) { - if (i > 2) { - ds_put_char(out, '\n'); - } list_record(must_get_row(ctx, table, ctx->argv[i]), columns, n_columns, out); } } else { const struct ovsdb_idl_row *row; - bool first; - for (row = ovsdb_idl_first_row(ctx->idl, table->class), first = true; - row != NULL; - row = ovsdb_idl_next_row(row), first = false) { - if (!first) { - ds_put_char(out, '\n'); - } + for (row = ovsdb_idl_first_row(ctx->idl, table->class); row != NULL; + row = ovsdb_idl_next_row(row)) { list_record(row, columns, n_columns, out); } } free(columns); } +static void +pre_cmd_find(struct vsctl_context *ctx) +{ + const char *column_names = shash_find_data(&ctx->options, "--columns"); + const char *table_name = ctx->argv[1]; + const struct vsctl_table_class *table; + int i; + + table = pre_get_table(ctx, table_name); + pre_list_columns(ctx, table, column_names); + for (i = 2; i < ctx->argc; i++) { + pre_parse_column_key_value(ctx, ctx->argv[i], table); + } +} + +static void +cmd_find(struct vsctl_context *ctx) +{ + const char *column_names = shash_find_data(&ctx->options, "--columns"); + const struct ovsdb_idl_column **columns; + const char *table_name = ctx->argv[1]; + const struct vsctl_table_class *table; + const struct ovsdb_idl_row *row; + struct table *out; + size_t n_columns; + + table = get_table(table_name); + parse_column_names(column_names, table, &columns, &n_columns); + out = ctx->table = list_make_table(columns, n_columns); + for (row = ovsdb_idl_first_row(ctx->idl, table->class); row; + row = ovsdb_idl_next_row(row)) { + int i; + + for (i = 2; i < ctx->argc; i++) { + if (!is_condition_satisfied(table, row, ctx->argv[i], + ctx->symtab)) { + goto next_row; + } + } + list_record(row, columns, n_columns, out); + + next_row: ; + } + free(columns); +} + static void pre_cmd_set(struct vsctl_context *ctx) { @@ -3031,18 +3308,42 @@ cmd_clear(struct vsctl_context *ctx) } static void -cmd_create(struct vsctl_context *ctx) +pre_create(struct vsctl_context *ctx) { const char *id = shash_find_data(&ctx->options, "--id"); const char *table_name = ctx->argv[1]; const struct vsctl_table_class *table; + + table = get_table(table_name); + if (!id && !table->class->is_root) { + VLOG_WARN("applying \"create\" command to table %s without --id " + "option will have no effect", table->class->name); + } +} + +static void +cmd_create(struct vsctl_context *ctx) +{ + const char *id = shash_find_data(&ctx->options, "--id"); + const char *table_name = ctx->argv[1]; + const struct vsctl_table_class *table = get_table(table_name); const struct ovsdb_idl_row *row; const struct uuid *uuid; int i; - uuid = id ? create_symbol(ctx->symtab, id, NULL) : NULL; + if (id) { + struct ovsdb_symbol *symbol = create_symbol(ctx->symtab, id, NULL); + if (table->class->is_root) { + /* This table is in the root set, meaning that rows created in it + * won't disappear even if they are unreferenced, so disable + * warnings about that by pretending that there is a reference. */ + symbol->strong_ref = true; + } + uuid = &symbol->uuid; + } else { + uuid = NULL; + } - table = get_table(table_name); row = ovsdb_idl_txn_insert(ctx->txn, table->class, uuid); for (i = 2; i < ctx->argc; i++) { set_column(table, row, ctx->argv[i], ctx->symtab); @@ -3065,7 +3366,9 @@ post_create(struct vsctl_context *ctx) const struct uuid *real; struct uuid dummy; - uuid_from_string(&dummy, ds_cstr(&ctx->output)); + if (!uuid_from_string(&dummy, ds_cstr(&ctx->output))) { + NOT_REACHED(); + } real = ovsdb_idl_txn_get_insert_uuid(ctx->txn, &dummy); if (real) { ds_clear(&ctx->output); @@ -3101,22 +3404,86 @@ cmd_destroy(struct vsctl_context *ctx) } } +#define RELOPS \ + RELOP(RELOP_EQ, "=") \ + RELOP(RELOP_NE, "!=") \ + RELOP(RELOP_LT, "<") \ + RELOP(RELOP_GT, ">") \ + RELOP(RELOP_LE, "<=") \ + RELOP(RELOP_GE, ">=") \ + RELOP(RELOP_SET_EQ, "{=}") \ + RELOP(RELOP_SET_NE, "{!=}") \ + RELOP(RELOP_SET_LT, "{<}") \ + RELOP(RELOP_SET_GT, "{>}") \ + RELOP(RELOP_SET_LE, "{<=}") \ + RELOP(RELOP_SET_GE, "{>=}") + +enum relop { +#define RELOP(ENUM, STRING) ENUM, + RELOPS +#undef RELOP +}; + +static bool +is_set_operator(enum relop op) +{ + return (op == RELOP_SET_EQ || op == RELOP_SET_NE || + op == RELOP_SET_LT || op == RELOP_SET_GT || + op == RELOP_SET_LE || op == RELOP_SET_GE); +} + +static bool +evaluate_relop(const struct ovsdb_datum *a, const struct ovsdb_datum *b, + const struct ovsdb_type *type, enum relop op) +{ + switch (op) { + case RELOP_EQ: + case RELOP_SET_EQ: + return ovsdb_datum_compare_3way(a, b, type) == 0; + case RELOP_NE: + case RELOP_SET_NE: + return ovsdb_datum_compare_3way(a, b, type) != 0; + case RELOP_LT: + return ovsdb_datum_compare_3way(a, b, type) < 0; + case RELOP_GT: + return ovsdb_datum_compare_3way(a, b, type) > 0; + case RELOP_LE: + return ovsdb_datum_compare_3way(a, b, type) <= 0; + case RELOP_GE: + return ovsdb_datum_compare_3way(a, b, type) >= 0; + + case RELOP_SET_LT: + return b->n > a->n && ovsdb_datum_includes_all(a, b, type); + case RELOP_SET_GT: + return a->n > b->n && ovsdb_datum_includes_all(b, a, type); + case RELOP_SET_LE: + return ovsdb_datum_includes_all(a, b, type); + case RELOP_SET_GE: + return ovsdb_datum_includes_all(b, a, type); + + default: + NOT_REACHED(); + } +} + static bool is_condition_satisfied(const struct vsctl_table_class *table, const struct ovsdb_idl_row *row, const char *arg, struct ovsdb_symbol_table *symtab) { static const char *operators[] = { - "=", "!=", "<", ">", "<=", ">=" +#define RELOP(ENUM, STRING) STRING, + RELOPS +#undef RELOP }; const struct ovsdb_idl_column *column; const struct ovsdb_datum *have_datum; char *key_string, *value_string; - const char *operator; - unsigned int idx; + struct ovsdb_type type; + int operator; + bool retval; char *error; - int cmp = 0; error = parse_column_key_value(arg, table, &column, &key_string, &operator, operators, ARRAY_SIZE(operators), @@ -3126,9 +3493,14 @@ is_condition_satisfied(const struct vsctl_table_class *table, vsctl_fatal("%s: missing value", arg); } + type = column->type; + type.n_max = UINT_MAX; + have_datum = ovsdb_idl_read(row, column); if (key_string) { - union ovsdb_atom want_key, want_value; + union ovsdb_atom want_key; + struct ovsdb_datum b; + unsigned int idx; if (column->type.value.type == OVSDB_TYPE_VOID) { vsctl_fatal("cannot specify key to check for non-map column %s", @@ -3137,41 +3509,45 @@ is_condition_satisfied(const struct vsctl_table_class *table, die_if_error(ovsdb_atom_from_string(&want_key, &column->type.key, key_string, symtab)); - die_if_error(ovsdb_atom_from_string(&want_value, &column->type.value, - value_string, symtab)); + + type.key = type.value; + type.value.type = OVSDB_TYPE_VOID; + die_if_error(ovsdb_datum_from_string(&b, &type, value_string, symtab)); idx = ovsdb_datum_find_key(have_datum, &want_key, column->type.key.type); - if (idx != UINT_MAX) { - cmp = ovsdb_atom_compare_3way(&have_datum->values[idx], - &want_value, - column->type.value.type); + if (idx == UINT_MAX && !is_set_operator(operator)) { + retval = false; + } else { + struct ovsdb_datum a; + + if (idx != UINT_MAX) { + a.n = 1; + a.keys = &have_datum->values[idx]; + a.values = NULL; + } else { + a.n = 0; + a.keys = NULL; + a.values = NULL; + } + + retval = evaluate_relop(&a, &b, &type, operator); } ovsdb_atom_destroy(&want_key, column->type.key.type); - ovsdb_atom_destroy(&want_value, column->type.value.type); } else { struct ovsdb_datum want_datum; die_if_error(ovsdb_datum_from_string(&want_datum, &column->type, value_string, symtab)); - idx = 0; - cmp = ovsdb_datum_compare_3way(have_datum, &want_datum, - &column->type); + retval = evaluate_relop(have_datum, &want_datum, &type, operator); ovsdb_datum_destroy(&want_datum, &column->type); } free(key_string); free(value_string); - return (idx == UINT_MAX ? false - : !strcmp(operator, "=") ? cmp == 0 - : !strcmp(operator, "!=") ? cmp != 0 - : !strcmp(operator, "<") ? cmp < 0 - : !strcmp(operator, ">") ? cmp > 0 - : !strcmp(operator, "<=") ? cmp <= 0 - : !strcmp(operator, ">=") ? cmp >= 0 - : (abort(), 0)); + return retval; } static void @@ -3238,6 +3614,7 @@ vsctl_context_init(struct vsctl_context *ctx, struct vsctl_command *command, ctx->options = command->options; ds_swap(&ctx->output, &command->output); + ctx->table = command->table; ctx->idl = idl; ctx->txn = txn; ctx->ovs = ovs; @@ -3251,6 +3628,7 @@ static void vsctl_context_done(struct vsctl_context *ctx, struct vsctl_command *command) { ds_swap(&ctx->output, &command->output); + command->table = ctx->table; } static void @@ -3268,17 +3646,19 @@ run_prerequisites(struct vsctl_command *commands, size_t n_commands, struct vsctl_context ctx; ds_init(&c->output); + c->table = NULL; vsctl_context_init(&ctx, c, idl, NULL, NULL, NULL); (c->syntax->prerequisites)(&ctx); vsctl_context_done(&ctx, c); assert(!c->output.string); + assert(!c->table); } } } -static void +static enum ovsdb_idl_txn_status do_vsctl(const char *args, struct vsctl_command *commands, size_t n_commands, struct ovsdb_idl *idl) { @@ -3286,8 +3666,8 @@ do_vsctl(const char *args, struct vsctl_command *commands, size_t n_commands, const struct ovsrec_open_vswitch *ovs; enum ovsdb_idl_txn_status status; struct ovsdb_symbol_table *symtab; - const char *unused; struct vsctl_command *c; + struct shash_node *node; int64_t next_cfg = 0; char *error = NULL; @@ -3313,19 +3693,43 @@ do_vsctl(const char *args, struct vsctl_command *commands, size_t n_commands, symtab = ovsdb_symbol_table_create(); for (c = commands; c < &commands[n_commands]; c++) { ds_init(&c->output); + c->table = NULL; } for (c = commands; c < &commands[n_commands]; c++) { struct vsctl_context ctx; vsctl_context_init(&ctx, c, idl, txn, ovs, symtab); - (c->syntax->run)(&ctx); + if (c->syntax->run) { + (c->syntax->run)(&ctx); + } vsctl_context_done(&ctx, c); if (ctx.try_again) { + status = TXN_AGAIN_WAIT; goto try_again; } } + SHASH_FOR_EACH (node, &symtab->sh) { + struct ovsdb_symbol *symbol = node->data; + if (!symbol->created) { + vsctl_fatal("row id \"%s\" is referenced but never created (e.g. " + "with \"-- --id=%s create ...\")", + node->name, node->name); + } + if (!symbol->strong_ref) { + if (!symbol->weak_ref) { + VLOG_WARN("row id \"%s\" was created but no reference to it " + "was inserted, so it will not actually appear in " + "the database", node->name); + } else { + VLOG_WARN("row id \"%s\" was created but only a weak " + "reference to it was inserted, so it will not " + "actually appear in the database", node->name); + } + } + } + status = ovsdb_idl_txn_commit_block(txn); if (wait_for_reload && status == TXN_SUCCESS) { next_cfg = ovsdb_idl_txn_get_increment_new_value(txn); @@ -3345,13 +3749,8 @@ do_vsctl(const char *args, struct vsctl_command *commands, size_t n_commands, ovsdb_idl_txn_destroy(txn); txn = the_idl_txn = NULL; - unused = ovsdb_symbol_table_find_unused(symtab); - if (unused) { - vsctl_fatal("row id \"%s\" is referenced but never created (e.g. " - "with \"-- --id=%s create ...\")", unused, unused); - } - switch (status) { + case TXN_UNCOMMITTED: case TXN_INCOMPLETE: NOT_REACHED(); @@ -3363,12 +3762,17 @@ do_vsctl(const char *args, struct vsctl_command *commands, size_t n_commands, case TXN_SUCCESS: break; - case TXN_TRY_AGAIN: + case TXN_AGAIN_WAIT: + case TXN_AGAIN_NOW: goto try_again; case TXN_ERROR: vsctl_fatal("transaction error: %s", error); + case TXN_NOT_LOCKED: + /* Should not happen--we never call ovsdb_idl_set_lock(). */ + vsctl_fatal("database not locked"); + default: NOT_REACHED(); } @@ -3379,7 +3783,9 @@ do_vsctl(const char *args, struct vsctl_command *commands, size_t n_commands, for (c = commands; c < &commands[n_commands]; c++) { struct ds *ds = &c->output; - if (oneline) { + if (c->table) { + table_print(c->table, &table_style); + } else if (oneline) { size_t j; ds_chomp(ds, '\n'); @@ -3403,6 +3809,8 @@ do_vsctl(const char *args, struct vsctl_command *commands, size_t n_commands, fputs(ds_cstr(ds), stdout); } ds_destroy(&c->output); + table_destroy(c->table); + free(c->table); smap_destroy(&c->options); } @@ -3435,13 +3843,18 @@ try_again: ovsdb_symbol_table_destroy(symtab); for (c = commands; c < &commands[n_commands]; c++) { ds_destroy(&c->output); + table_destroy(c->table); + free(c->table); } free(error); + + return status; } static const struct vsctl_command_syntax all_commands[] = { /* Open vSwitch commands. */ {"init", 0, 0, NULL, cmd_init, NULL, "", RW}, + {"show", 0, 0, pre_cmd_show, cmd_show, NULL, "", RO}, /* Bridge commands. */ {"add-br", 1, 3, pre_get_info, cmd_add_br, NULL, "--may-exist", RW}, @@ -3491,14 +3904,16 @@ static const struct vsctl_command_syntax all_commands[] = { /* Switch commands. */ {"emer-reset", 0, 0, pre_cmd_emer_reset, cmd_emer_reset, NULL, "", RW}, - /* Parameter commands. */ + /* Database commands. */ + {"comment", 0, INT_MAX, NULL, NULL, NULL, "", RO}, {"get", 2, INT_MAX, pre_cmd_get, cmd_get, NULL, "--if-exists,--id=", RO}, {"list", 1, INT_MAX, pre_cmd_list, cmd_list, NULL, "--columns=", RO}, + {"find", 1, INT_MAX, pre_cmd_find, cmd_find, NULL, "--columns=", RO}, {"set", 3, INT_MAX, pre_cmd_set, cmd_set, NULL, "", RW}, {"add", 4, INT_MAX, pre_cmd_add, cmd_add, NULL, "", RW}, {"remove", 4, INT_MAX, pre_cmd_remove, cmd_remove, NULL, "", RW}, {"clear", 3, INT_MAX, pre_cmd_clear, cmd_clear, NULL, "", RW}, - {"create", 2, INT_MAX, NULL, cmd_create, post_create, "--id=", RW}, + {"create", 2, INT_MAX, pre_create, cmd_create, post_create, "--id=", RW}, {"destroy", 1, INT_MAX, pre_cmd_destroy, cmd_destroy, NULL, "--if-exists", RW}, {"wait-until", 2, INT_MAX, pre_cmd_wait_until, cmd_wait_until, NULL, "",