summaryrefslogtreecommitdiff
path: root/ovsdb/execution.c
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2011-07-26 10:24:17 -0700
committerBen Pfaff <blp@nicira.com>2011-07-26 16:50:09 -0700
commitda897f41cd795e325ec5ce773a70a819100bd26e (patch)
tree23635409122e1f95c3a73af8b8f50b8495ab0ef6 /ovsdb/execution.c
parente317253b1391c7b0a84c8dd51eaf1f3cc16eff56 (diff)
downloadopenvswitch-da897f41cd795e325ec5ce773a70a819100bd26e.tar.gz
ovsdb: Implement a "lock" feature in the database protocol.
This provides clients a way to coordinate their access to the database. This is a voluntary, not mandatory, locking protocols, that is, clients are not prevented from modifying the database unless they cooperate with the locking protocol. It is also not related to any of the ACID properties of database transactions. It is strictly a way for clients to coordinate among themselves. The following commit will introduce one user.
Diffstat (limited to 'ovsdb/execution.c')
-rw-r--r--ovsdb/execution.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/ovsdb/execution.c b/ovsdb/execution.c
index 416016fd9..9e3a8d07b 100644
--- a/ovsdb/execution.c
+++ b/ovsdb/execution.c
@@ -29,12 +29,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 +59,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 +79,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 +94,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 +121,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;
@@ -706,3 +712,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_STRING);
+ 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));
+}