#include "table.h"
#include <assert.h>
+#include <limits.h>
#include "json.h"
#include "column.h"
}
struct ovsdb_table_schema *
-ovsdb_table_schema_create(const char *name, 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->name = xstrdup(name);
ts->mutable = mutable;
shash_init(&ts->columns);
+ ts->max_rows = max_rows;
uuid = ovsdb_column_create("_uuid", false, true, &ovsdb_type_uuid);
add_column(ts, uuid);
struct ovsdb_table_schema *new;
struct shash_node *node;
- new = ovsdb_table_schema_create(old->name, 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;
struct ovsdb_table_schema **tsp)
{
struct ovsdb_table_schema *ts;
- const struct json *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;
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,
- 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;
}
}
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;
}
if (table) {
struct ovsdb_row *row, *next;
- HMAP_FOR_EACH_SAFE (row, next, struct ovsdb_row, hmap_node,
- &table->rows) {
+ HMAP_FOR_EACH_SAFE (row, next, hmap_node, &table->rows) {
ovsdb_row_destroy(row);
}
hmap_destroy(&table->rows);
{
struct ovsdb_row *row;
- HMAP_FOR_EACH_WITH_HASH (row, struct ovsdb_row, hmap_node, uuid_hash(uuid),
- &table->rows) {
+ HMAP_FOR_EACH_WITH_HASH (row, hmap_node, uuid_hash(uuid), &table->rows) {
if (uuid_equals(ovsdb_row_get_uuid(row), uuid)) {
return row;
}