diff options
| author | Ben Pfaff <blp@nicira.com> | 2010-03-16 17:08:06 -0700 |
|---|---|---|
| committer | Ben Pfaff <blp@nicira.com> | 2010-03-18 11:32:26 -0700 |
| commit | 87ab878cadeb8cf5f8f89a7d00bfc64ee6b4edbf (patch) | |
| tree | bc2b286d73121c22013973e69b280816da28011c /ovsdb/transaction.c | |
| parent | 0cd85e1b0b35eaebe458f1d40c0df8c35d9d7e21 (diff) | |
| download | openvswitch-87ab878cadeb8cf5f8f89a7d00bfc64ee6b4edbf.tar.gz | |
ovsdb: Allow constraining the number of rows in a table.
Diffstat (limited to 'ovsdb/transaction.c')
| -rw-r--r-- | ovsdb/transaction.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/ovsdb/transaction.c b/ovsdb/transaction.c index 2e4c73a82..218fbce3e 100644 --- a/ovsdb/transaction.c +++ b/ovsdb/transaction.c @@ -441,6 +441,27 @@ determine_changes(struct ovsdb_txn *txn, struct ovsdb_txn_row *txn_row) return NULL; } +static struct ovsdb_error * WARN_UNUSED_RESULT +check_max_rows(struct ovsdb_txn *txn) +{ + struct ovsdb_txn_table *t; + + LIST_FOR_EACH (t, struct ovsdb_txn_table, node, &txn->txn_tables) { + size_t n_rows = hmap_count(&t->table->rows); + unsigned int max_rows = t->table->schema->max_rows; + + if (n_rows > max_rows) { + return ovsdb_error("constraint violation", + "transaction causes \"%s\" table to contain " + "%zu rows, greater than the schema-defined " + "limit of %u row(s)", + t->table->schema->name, n_rows, max_rows); + } + } + + return NULL; +} + struct ovsdb_error * ovsdb_txn_commit(struct ovsdb_txn *txn, bool durable) { @@ -459,6 +480,13 @@ ovsdb_txn_commit(struct ovsdb_txn *txn, bool durable) return NULL; } + /* Check maximum rows table constraints. */ + error = check_max_rows(txn); + if (error) { + ovsdb_txn_abort(txn); + return error; + } + /* Update reference counts and check referential integrity. */ error = update_ref_counts(txn); if (error) { |
