summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2010-06-08 17:11:40 +0930
committerRusty Russell <rusty@rustcorp.com.au>2010-06-08 17:11:40 +0930
commit7589b58138e50b0285d5b6d1e2848a3e22cbc228 (patch)
treeac63ffdba6d55fbabb5eb5ecb03a776d342d39fe
parent866cca963757c10482e3baf91205fa0d22b78067 (diff)
downloadsamba-7589b58138e50b0285d5b6d1e2848a3e22cbc228.tar.gz
samba-7589b58138e50b0285d5b6d1e2848a3e22cbc228.tar.xz
samba-7589b58138e50b0285d5b6d1e2848a3e22cbc228.zip
libctdb: more bool conversion, and accompany lock by ctdb_db in API
I missed some int->bool conversions previously, particularly the return of ctdb_writerecord(). By always handing functions ctdb_connection or ctdb_db, we keep it consistent with the rest of the API and can do extra lock consistency checks. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (This used to be ctdb commit 3f939956ddd693cba6ea5c655288f4f5ca95f768)
-rw-r--r--ctdb/include/ctdb.h11
-rw-r--r--ctdb/libctdb/ctdb.c31
-rw-r--r--ctdb/libctdb/sync.c2
-rw-r--r--ctdb/libctdb/tst.c8
4 files changed, 34 insertions, 18 deletions
diff --git a/ctdb/include/ctdb.h b/ctdb/include/ctdb.h
index 93e6c13f1c..e4aff86723 100644
--- a/ctdb/include/ctdb.h
+++ b/ctdb/include/ctdb.h
@@ -204,7 +204,7 @@ struct ctdb_db;
*/
struct ctdb_request *
ctdb_attachdb_send(struct ctdb_connection *ctdb,
- const char *name, int persistent, uint32_t tdb_flags,
+ const char *name, bool persistent, uint32_t tdb_flags,
ctdb_callback_t callback, void *cbdata);
/**
@@ -268,16 +268,19 @@ bool ctdb_readrecordlock_async(struct ctdb_db *ctdb_db, TDB_DATA key,
/**
* ctdb_writerecord - write a locked record in a TDB
+ * @ctdb_db: the database handle from ctdb_attachdb/ctdb_attachdb_recv.
* @lock: the lock from ctdb_readrecordlock/ctdb_readrecordlock_recv
* @data: the new data to place in the record.
*/
-int ctdb_writerecord(struct ctdb_lock *lock, TDB_DATA data);
+bool ctdb_writerecord(struct ctdb_db *ctdb_db,
+ struct ctdb_lock *lock, TDB_DATA data);
/**
* ctdb_release_lock - release a record lock on a TDB
+ * @ctdb_db: the database handle from ctdb_attachdb/ctdb_attachdb_recv.
* @lock: the lock from ctdb_readrecordlock/ctdb_readrecordlock_async
*/
-void ctdb_release_lock(struct ctdb_lock *lock);
+void ctdb_release_lock(struct ctdb_db *ctdb_db, struct ctdb_lock *lock);
/**
* ctdb_message_fn_t - messaging callback for ctdb messages
@@ -450,7 +453,7 @@ void ctdb_cancel(struct ctdb_connection *ctdb, struct ctdb_request *req);
* Returns NULL on failure.
*/
struct ctdb_db *ctdb_attachdb(struct ctdb_connection *ctdb,
- const char *name, int persistent,
+ const char *name, bool persistent,
uint32_t tdb_flags);
/**
diff --git a/ctdb/libctdb/ctdb.c b/ctdb/libctdb/ctdb.c
index afe7e1dff7..4a74bf7aed 100644
--- a/ctdb/libctdb/ctdb.c
+++ b/ctdb/libctdb/ctdb.c
@@ -588,7 +588,7 @@ static void destroy_req_db(struct ctdb_connection *ctdb,
struct ctdb_request *
ctdb_attachdb_send(struct ctdb_connection *ctdb,
- const char *name, int persistent, uint32_t tdb_flags,
+ const char *name, bool persistent, uint32_t tdb_flags,
ctdb_callback_t callback, void *private_data)
{
struct ctdb_request *req;
@@ -654,11 +654,15 @@ static void free_lock(struct ctdb_lock *lock)
}
-void ctdb_release_lock(struct ctdb_lock *lock)
+void ctdb_release_lock(struct ctdb_db *ctdb_db, struct ctdb_lock *lock)
{
if (lock->held_magic != lock_magic(lock)) {
DEBUG(lock->ctdb_db->ctdb, LOG_ALERT,
"ctdb_release_lock invalid lock %p", lock);
+ } else if (lock->ctdb_db != ctdb_db) {
+ errno = EBADF;
+ DEBUG(ctdb_db->ctdb, LOG_ALERT,
+ "ctdb_release_lock: wrong ctdb_db.");
} else {
tdb_chainunlock(lock->ctdb_db->tdb, lock->key);
DEBUG(lock->ctdb_db->ctdb, LOG_DEBUG,
@@ -798,22 +802,29 @@ ctdb_readrecordlock_async(struct ctdb_db *ctdb_db, TDB_DATA key,
return true;
}
-int ctdb_writerecord(struct ctdb_lock *lock, TDB_DATA data)
+bool ctdb_writerecord(struct ctdb_db *ctdb_db,
+ struct ctdb_lock *lock, TDB_DATA data)
{
+ if (lock->ctdb_db != ctdb_db) {
+ errno = EBADF;
+ DEBUG(ctdb_db->ctdb, LOG_ALERT,
+ "ctdb_writerecord: Can not write, wrong ctdb_db.");
+ return false;
+ }
+
if (lock->held_magic != lock_magic(lock)) {
errno = EBADF;
- DEBUG(lock->ctdb_db->ctdb, LOG_ALERT,
+ DEBUG(ctdb_db->ctdb, LOG_ALERT,
"ctdb_writerecord: Can not write. Lock has been released.");
- return -1;
+ return false;
}
- if (lock->ctdb_db->persistent) {
+ if (ctdb_db->persistent) {
errno = EINVAL;
- DEBUG(lock->ctdb_db->ctdb, LOG_ALERT,
+ DEBUG(ctdb_db->ctdb, LOG_ALERT,
"ctdb_writerecord: cannot write to persistent db");
- return -1;
+ return false;
}
- return ctdb_local_store(lock->ctdb_db->tdb, lock->key, lock->hdr,
- data);
+ return ctdb_local_store(ctdb_db->tdb, lock->key, lock->hdr, data) == 0;
}
diff --git a/ctdb/libctdb/sync.c b/ctdb/libctdb/sync.c
index 3ee33011a2..11cd6cad74 100644
--- a/ctdb/libctdb/sync.c
+++ b/ctdb/libctdb/sync.c
@@ -77,7 +77,7 @@ bool ctdb_getrecmaster(struct ctdb_connection *ctdb,
}
struct ctdb_db *ctdb_attachdb(struct ctdb_connection *ctdb,
- const char *name, int persistent,
+ const char *name, bool persistent,
uint32_t tdb_flags)
{
struct ctdb_request *req;
diff --git a/ctdb/libctdb/tst.c b/ctdb/libctdb/tst.c
index 391e92c727..9f67b62921 100644
--- a/ctdb/libctdb/tst.c
+++ b/ctdb/libctdb/tst.c
@@ -107,10 +107,11 @@ static void rrl_cb(struct ctdb_db *ctdb_db,
data.dptr = tmp;
data.dsize = strlen(tmp) + 1;
- ctdb_writerecord(lock, data);
+ if (!ctdb_writerecord(ctdb_db, lock, data))
+ printf("Error writing data!\n");
/* Release the lock as quickly as possible */
- ctdb_release_lock(lock);
+ ctdb_release_lock(ctdb_db, lock);
printf("Wrote new record : %s\n", tmp);
@@ -172,7 +173,8 @@ int main(int argc, char *argv[])
exit(10);
}
- ctdb_db_context = ctdb_attachdb(ctdb_connection, "test_test.tdb", 0, 0);
+ ctdb_db_context = ctdb_attachdb(ctdb_connection, "test_test.tdb",
+ false, 0);
if (!ctdb_db_context) {
printf("Failed to attach to database\n");
exit(10);