X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=ovsdb%2Ftable.c;h=6a4e7ae2f4fc5a6f232754e9aaea7b3205c42df8;hb=86f2fa597c6eb8eb1c9a42685200c0ac90b85e97;hp=7ba47eb012a4c8a194b29fb5c89d7c389780fdf0;hpb=02dd3123a0e312f1d33403e744af52dd6096f12d;p=sliver-openvswitch.git diff --git a/ovsdb/table.c b/ovsdb/table.c index 7ba47eb01..6a4e7ae2f 100644 --- a/ovsdb/table.c +++ b/ovsdb/table.c @@ -18,6 +18,7 @@ #include "table.h" #include +#include #include "json.h" #include "column.h" @@ -35,26 +36,23 @@ add_column(struct ovsdb_table_schema *ts, struct ovsdb_column *column) } struct ovsdb_table_schema * -ovsdb_table_schema_create(const char *name, const char *comment, bool mutable) +ovsdb_table_schema_create(const char *name, bool mutable, + unsigned int max_rows) { struct ovsdb_column *uuid, *version; struct ovsdb_table_schema *ts; ts = xzalloc(sizeof *ts); ts->name = xstrdup(name); - ts->comment = comment ? xstrdup(comment) : NULL; ts->mutable = mutable; shash_init(&ts->columns); + ts->max_rows = max_rows; - uuid = ovsdb_column_create( - "_uuid", "Unique identifier for this row.", - false, true, &ovsdb_type_uuid); + uuid = ovsdb_column_create("_uuid", false, true, &ovsdb_type_uuid); add_column(ts, uuid); assert(uuid->index == OVSDB_COL_UUID); - version = ovsdb_column_create( - "_version", "Unique identifier for this version of this row.", - false, false, &ovsdb_type_uuid); + version = ovsdb_column_create("_version", false, false, &ovsdb_type_uuid); add_column(ts, version); assert(version->index == OVSDB_COL_VERSION); @@ -67,7 +65,7 @@ ovsdb_table_schema_clone(const struct ovsdb_table_schema *old) struct ovsdb_table_schema *new; struct shash_node *node; - new = ovsdb_table_schema_create(old->name, old->comment, old->mutable); + new = ovsdb_table_schema_create(old->name, old->mutable, old->max_rows); SHASH_FOR_EACH (node, &old->columns) { const struct ovsdb_column *column = node->data; @@ -90,7 +88,6 @@ ovsdb_table_schema_destroy(struct ovsdb_table_schema *ts) ovsdb_column_destroy(node->data); } shash_destroy(&ts->columns); - free(ts->comment); free(ts->name); free(ts); } @@ -100,31 +97,43 @@ ovsdb_table_schema_from_json(const struct json *json, const char *name, struct ovsdb_table_schema **tsp) { struct ovsdb_table_schema *ts; - const struct json *comment, *columns, *mutable; + const struct json *columns, *mutable, *max_rows; struct shash_node *node; struct ovsdb_parser parser; struct ovsdb_error *error; + long long int n_max_rows; *tsp = NULL; ovsdb_parser_init(&parser, json, "table schema for table %s", name); - comment = ovsdb_parser_member(&parser, "comment", OP_STRING | OP_OPTIONAL); columns = ovsdb_parser_member(&parser, "columns", OP_OBJECT); mutable = ovsdb_parser_member(&parser, "mutable", OP_TRUE | OP_FALSE | OP_OPTIONAL); + max_rows = ovsdb_parser_member(&parser, "maxRows", + OP_INTEGER | OP_OPTIONAL); error = ovsdb_parser_finish(&parser); if (error) { return error; } + if (max_rows) { + if (json_integer(max_rows) <= 0) { + return ovsdb_syntax_error(json, NULL, + "maxRows must be at least 1"); + } + n_max_rows = max_rows->u.integer; + } else { + n_max_rows = UINT_MAX; + } + if (shash_is_empty(json_object(columns))) { return ovsdb_syntax_error(json, NULL, "table must have at least one column"); } ts = ovsdb_table_schema_create(name, - comment ? json_string(comment) : NULL, - mutable ? json_boolean(mutable) : true); + mutable ? json_boolean(mutable) : true, + MIN(n_max_rows, UINT_MAX)); SHASH_FOR_EACH (node, json_object(columns)) { struct ovsdb_column *column; @@ -154,9 +163,6 @@ ovsdb_table_schema_to_json(const struct ovsdb_table_schema *ts) struct shash_node *node; json = json_object_create(); - if (ts->comment) { - json_object_put_string(json, "comment", ts->comment); - } if (!ts->mutable) { json_object_put(json, "mutable", json_boolean_create(false)); } @@ -171,6 +177,9 @@ ovsdb_table_schema_to_json(const struct ovsdb_table_schema *ts) } } json_object_put(json, "columns", columns); + if (ts->max_rows != UINT_MAX) { + json_object_put(json, "maxRows", json_integer_create(ts->max_rows)); + } return json; }