X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=utilities%2Fovs-vsctl.c;h=9d34267b9ed4f30820fb766e5e7d9ef12836951f;hb=d78ac3883fd1511505aa3f13db2a571015b03bf2;hp=9b4019777362dc68844ee72789623416fc9a776c;hpb=4a0335937fb482e412952a5e05ef738eab9542dc;p=openvswitch diff --git a/utilities/ovs-vsctl.c b/utilities/ovs-vsctl.c index 9b401977..9d34267b 100644 --- a/utilities/ovs-vsctl.c +++ b/utilities/ovs-vsctl.c @@ -111,14 +111,14 @@ static void do_vsctl(const char *args, 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); + const struct ovsdb_idl_row *, const char *arg, + struct ovsdb_symbol_table *); int main(int argc, char *argv[]) { struct ovsdb_idl *idl; - unsigned int seqno; struct vsctl_command *commands; size_t n_commands; char *args; @@ -146,19 +146,13 @@ main(int argc, char *argv[]) /* Now execute the commands. */ idl = the_idl = ovsdb_idl_create(db, &ovsrec_idl_class); - seqno = ovsdb_idl_get_seqno(idl); trials = 0; for (;;) { - unsigned int new_seqno; - - ovsdb_idl_run(idl); - new_seqno = ovsdb_idl_get_seqno(idl); - if (new_seqno != seqno) { + if (ovsdb_idl_run(idl)) { if (++trials > 5) { vsctl_fatal("too many database inconsistency failures"); } do_vsctl(args, commands, n_commands, idl); - seqno = new_seqno; } ovsdb_idl_wait(idl); @@ -511,6 +505,7 @@ struct vsctl_context { struct ds output; struct ovsdb_idl *idl; struct ovsdb_idl_txn *txn; + struct ovsdb_symbol_table *symtab; const struct ovsrec_open_vswitch *ovs; }; @@ -622,17 +617,8 @@ free_info(struct vsctl_info *info) } shash_destroy(&info->bridges); - SHASH_FOR_EACH (node, &info->ports) { - struct vsctl_port *port = node->data; - free(port); - } - shash_destroy(&info->ports); - - SHASH_FOR_EACH (node, &info->ifaces) { - struct vsctl_iface *iface = node->data; - free(iface); - } - shash_destroy(&info->ifaces); + shash_destroy_free_data(&info->ports); + shash_destroy_free_data(&info->ifaces); } static void @@ -1384,7 +1370,8 @@ add_port(struct vsctl_context *ctx, } for (i = 0; i < n_settings; i++) { - set_column(get_table("Port"), &port->header_, settings[i]); + set_column(get_table("Port"), &port->header_, settings[i], + ctx->symtab); } bridge_insert_port((bridge->parent ? bridge->parent->br_cfg @@ -1901,6 +1888,14 @@ static const struct vsctl_table_class tables[] = { {{&ovsrec_table_port, &ovsrec_port_col_name, NULL}, {NULL, NULL, NULL}}}, + {&ovsrec_table_qos, + {{&ovsrec_table_port, &ovsrec_port_col_name, &ovsrec_port_col_qos}, + {NULL, NULL, NULL}}}, + + {&ovsrec_table_queue, + {{NULL, NULL, NULL}, + {NULL, NULL, NULL}}}, + {&ovsrec_table_ssl, {{&ovsrec_table_open_vswitch, NULL, &ovsrec_open_vswitch_col_ssl}}}, @@ -2229,7 +2224,7 @@ cmd_get(struct vsctl_context *ctx) die_if_error(ovsdb_atom_from_string(&key, &column->type.key, - key_string)); + key_string, ctx->symtab)); idx = ovsdb_datum_find_key(&datum, &key, column->type.key.type); @@ -2309,7 +2304,8 @@ cmd_list(struct vsctl_context *ctx) static void set_column(const struct vsctl_table_class *table, - const struct ovsdb_idl_row *row, const char *arg) + 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; @@ -2332,9 +2328,9 @@ set_column(const struct vsctl_table_class *table, } die_if_error(ovsdb_atom_from_string(&key, &column->type.key, - key_string)); + key_string, symtab)); die_if_error(ovsdb_atom_from_string(&value, &column->type.value, - value_string)); + value_string, symtab)); ovsdb_datum_init_empty(&new); ovsdb_datum_add_unsafe(&new, &key, &value, &column->type); @@ -2351,7 +2347,7 @@ set_column(const struct vsctl_table_class *table, struct ovsdb_datum datum; die_if_error(ovsdb_datum_from_string(&datum, &column->type, - value_string)); + value_string, symtab)); ovsdb_idl_txn_write(row, column, &datum); } @@ -2371,7 +2367,7 @@ cmd_set(struct vsctl_context *ctx) table = get_table(table_name); row = must_get_row(ctx, table, record_id); for (i = 3; i < ctx->argc; i++) { - set_column(table, row, ctx->argv[i]); + set_column(table, row, ctx->argv[i], ctx->symtab); } } @@ -2401,7 +2397,8 @@ cmd_add(struct vsctl_context *ctx) add_type = *type; add_type.n_min = 1; add_type.n_max = UINT_MAX; - die_if_error(ovsdb_datum_from_string(&add, &add_type, ctx->argv[i])); + die_if_error(ovsdb_datum_from_string(&add, &add_type, ctx->argv[i], + ctx->symtab)); ovsdb_datum_union(&old, &add, type, false); ovsdb_datum_destroy(&add, type); } @@ -2442,11 +2439,13 @@ cmd_remove(struct vsctl_context *ctx) rm_type = *type; rm_type.n_min = 1; rm_type.n_max = UINT_MAX; - error = ovsdb_datum_from_string(&rm, &rm_type, ctx->argv[i]); + error = ovsdb_datum_from_string(&rm, &rm_type, + ctx->argv[i], ctx->symtab); if (error && ovsdb_type_is_map(&rm_type)) { free(error); rm_type.value.type = OVSDB_TYPE_VOID; - die_if_error(ovsdb_datum_from_string(&rm, &rm_type, ctx->argv[i])); + die_if_error(ovsdb_datum_from_string(&rm, &rm_type, + ctx->argv[i], ctx->symtab)); } ovsdb_datum_subtract(&old, type, &rm, &rm_type); ovsdb_datum_destroy(&rm, &rm_type); @@ -2494,15 +2493,36 @@ cmd_clear(struct vsctl_context *ctx) 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; const struct ovsdb_idl_row *row; + const struct uuid *uuid; int i; + if (id) { + struct ovsdb_symbol *symbol; + + if (id[0] != '@') { + vsctl_fatal("row id \"%s\" does not begin with \"@\"", id); + } + + symbol = ovsdb_symbol_table_insert(ctx->symtab, id); + if (symbol->used) { + vsctl_fatal("row id \"%s\" may only be used to insert a single " + "row", id); + } + symbol->used = true; + + uuid = &symbol->uuid; + } else { + uuid = NULL; + } + table = get_table(table_name); - row = ovsdb_idl_txn_insert(ctx->txn, table->class); + row = ovsdb_idl_txn_insert(ctx->txn, table->class, uuid); for (i = 2; i < ctx->argc; i++) { - set_column(table, row, ctx->argv[i]); + set_column(table, row, ctx->argv[i], ctx->symtab); } ds_put_format(&ctx->output, UUID_FMT, UUID_ARGS(&row->uuid)); } @@ -2567,7 +2587,8 @@ where_uuid_equals(const struct uuid *uuid) static void vsctl_context_init(struct vsctl_context *ctx, struct vsctl_command *command, struct ovsdb_idl *idl, struct ovsdb_idl_txn *txn, - const struct ovsrec_open_vswitch *ovs) + const struct ovsrec_open_vswitch *ovs, + struct ovsdb_symbol_table *symtab) { ctx->argc = command->argc; ctx->argv = command->argv; @@ -2577,7 +2598,7 @@ vsctl_context_init(struct vsctl_context *ctx, struct vsctl_command *command, ctx->idl = idl; ctx->txn = txn; ctx->ovs = ovs; - + ctx->symtab = symtab; } static void @@ -2593,6 +2614,8 @@ do_vsctl(const char *args, struct vsctl_command *commands, size_t n_commands, struct ovsdb_idl_txn *txn; const struct ovsrec_open_vswitch *ovs; enum ovsdb_idl_txn_status status; + struct ovsdb_symbol_table *symtab; + const char *unused; struct vsctl_command *c; int64_t next_cfg = 0; char *error; @@ -2616,11 +2639,12 @@ do_vsctl(const char *args, struct vsctl_command *commands, size_t n_commands, json_destroy(where); } + symtab = ovsdb_symbol_table_create(); for (c = commands; c < &commands[n_commands]; c++) { struct vsctl_context ctx; ds_init(&c->output); - vsctl_context_init(&ctx, c, idl, txn, ovs); + vsctl_context_init(&ctx, c, idl, txn, ovs, symtab); (c->syntax->run)(&ctx); vsctl_context_done(&ctx, c); } @@ -2634,7 +2658,7 @@ do_vsctl(const char *args, struct vsctl_command *commands, size_t n_commands, if (c->syntax->postprocess) { struct vsctl_context ctx; - vsctl_context_init(&ctx, c, idl, txn, ovs); + vsctl_context_init(&ctx, c, idl, txn, ovs, symtab); (c->syntax->postprocess)(&ctx); vsctl_context_done(&ctx, c); } @@ -2644,6 +2668,13 @@ do_vsctl(const char *args, struct vsctl_command *commands, size_t n_commands, ovsdb_idl_txn_destroy(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); + } + ovsdb_symbol_table_destroy(symtab); + switch (status) { case TXN_INCOMPLETE: NOT_REACHED(); @@ -2673,6 +2704,8 @@ 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; + struct shash_node *node; + if (oneline) { size_t j; @@ -2697,6 +2730,10 @@ do_vsctl(const char *args, struct vsctl_command *commands, size_t n_commands, fputs(ds_cstr(ds), stdout); } ds_destroy(&c->output); + + SHASH_FOR_EACH (node, &c->options) { + free(node->data); + } shash_destroy(&c->options); } free(commands); @@ -2769,7 +2806,7 @@ static const struct vsctl_command_syntax all_commands[] = { {"add", 4, INT_MAX, cmd_add, NULL, ""}, {"remove", 4, INT_MAX, cmd_remove, NULL, ""}, {"clear", 3, INT_MAX, cmd_clear, NULL, ""}, - {"create", 2, INT_MAX, cmd_create, post_create, ""}, + {"create", 2, INT_MAX, cmd_create, post_create, "--id="}, {"destroy", 1, INT_MAX, cmd_destroy, NULL, "--if-exists"}, {NULL, 0, 0, NULL, NULL, NULL},