X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=ovsdb%2Fexecution.c;h=027e9e18bb5c5ed455381031bcbee11945332f85;hb=fd76a6f94338b668175336434b156827458b5e7d;hp=416016fd9ef3ff89758d6c87bd51653f6e54f51a;hpb=1cb29ab050c601448a89eb7311a9f07095921bbd;p=sliver-openvswitch.git diff --git a/ovsdb/execution.c b/ovsdb/execution.c index 416016fd9..027e9e18b 100644 --- a/ovsdb/execution.c +++ b/ovsdb/execution.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2009, 2010, 2011 Nicira Networks +/* Copyright (c) 2009, 2010, 2011, 2012 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,6 @@ #include -#include #include #include "column.h" @@ -29,12 +28,14 @@ #include "ovsdb.h" #include "query.h" #include "row.h" +#include "server.h" #include "table.h" #include "timeval.h" #include "transaction.h" struct ovsdb_execution { struct ovsdb *db; + const struct ovsdb_session *session; struct ovsdb_txn *txn; struct ovsdb_symbol_table *symtab; bool durable; @@ -57,6 +58,7 @@ static ovsdb_operation_executor ovsdb_execute_wait; static ovsdb_operation_executor ovsdb_execute_commit; static ovsdb_operation_executor ovsdb_execute_abort; static ovsdb_operation_executor ovsdb_execute_comment; +static ovsdb_operation_executor ovsdb_execute_assert; static ovsdb_operation_executor * lookup_executor(const char *name) @@ -76,6 +78,7 @@ lookup_executor(const char *name) { "commit", ovsdb_execute_commit }, { "abort", ovsdb_execute_abort }, { "comment", ovsdb_execute_comment }, + { "assert", ovsdb_execute_assert }, }; size_t i; @@ -90,7 +93,8 @@ lookup_executor(const char *name) } struct json * -ovsdb_execute(struct ovsdb *db, const struct json *params, +ovsdb_execute(struct ovsdb *db, const struct ovsdb_session *session, + const struct json *params, long long int elapsed_msec, long long int *timeout_msec) { struct ovsdb_execution x; @@ -116,6 +120,7 @@ ovsdb_execute(struct ovsdb *db, const struct json *params, } x.db = db; + x.session = session; x.txn = ovsdb_txn_create(db); x.symtab = ovsdb_symbol_table_create(); x.durable = false; @@ -148,7 +153,7 @@ ovsdb_execute(struct ovsdb *db, const struct json *params, op_name); } } else { - assert(ovsdb_parser_has_error(&parser)); + ovs_assert(ovsdb_parser_has_error(&parser)); } /* A parse error overrides any other error. @@ -428,6 +433,22 @@ ovsdb_execute_update(struct ovsdb_execution *x, struct ovsdb_parser *parser, if (!error) { error = parse_row(row_json, table, x->symtab, &row, &columns); } + if (!error) { + size_t i; + + for (i = 0; i < columns.n_columns; i++) { + const struct ovsdb_column *column = columns.columns[i]; + + if (!column->mutable) { + error = ovsdb_syntax_error(parser->json, + "constraint violation", + "Cannot update immutable column %s " + "in table %s.", + column->name, table->schema->name); + break; + } + } + } if (!error) { error = ovsdb_condition_from_json(table->schema, where, x->symtab, &condition); @@ -706,3 +727,28 @@ ovsdb_execute_comment(struct ovsdb_execution *x, struct ovsdb_parser *parser, return NULL; } + +static struct ovsdb_error * +ovsdb_execute_assert(struct ovsdb_execution *x, struct ovsdb_parser *parser, + struct json *result OVS_UNUSED) +{ + const struct json *lock_name; + + lock_name = ovsdb_parser_member(parser, "lock", OP_ID); + if (!lock_name) { + return NULL; + } + + if (x->session) { + const struct ovsdb_lock_waiter *waiter; + + waiter = ovsdb_session_get_lock_waiter(x->session, + json_string(lock_name)); + if (waiter && ovsdb_lock_waiter_is_owner(waiter)) { + return NULL; + } + } + + return ovsdb_error("not owner", "Asserted lock %s not held.", + json_string(lock_name)); +}