diff options
author | Rusty Russell <rusty@rustcorp.com.au> | 2010-06-08 17:11:40 +0930 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2010-06-08 17:11:40 +0930 |
commit | 7589b58138e50b0285d5b6d1e2848a3e22cbc228 (patch) | |
tree | ac63ffdba6d55fbabb5eb5ecb03a776d342d39fe /ctdb/libctdb/ctdb.c | |
parent | 866cca963757c10482e3baf91205fa0d22b78067 (diff) | |
download | samba-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)
Diffstat (limited to 'ctdb/libctdb/ctdb.c')
-rw-r--r-- | ctdb/libctdb/ctdb.c | 31 |
1 files changed, 21 insertions, 10 deletions
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; } |