diff options
| author | Andrew Tridgell <tridge@samba.org> | 2007-05-10 17:43:08 +1000 |
|---|---|---|
| committer | Andrew Tridgell <tridge@samba.org> | 2007-05-10 17:43:08 +1000 |
| commit | 698d2a6af49a3d7a8a9b2abbce344d6c853e050a (patch) | |
| tree | e870c61d74789e6d2658acea2e4d0df8cb7e4c26 /ctdb/lib | |
| parent | 15bc97cdaa9ce7d175396bca3860540f2c4cfe67 (diff) | |
added nonblocking varients of the two lockall functions to tdb
(This used to be ctdb commit 2e99fa41ce01fa282bc0f3244ca42a78173743ed)
Diffstat (limited to 'ctdb/lib')
| -rw-r--r-- | ctdb/lib/tdb/common/lock.c | 26 | ||||
| -rw-r--r-- | ctdb/lib/tdb/include/tdb.h | 2 |
2 files changed, 23 insertions, 5 deletions
diff --git a/ctdb/lib/tdb/common/lock.c b/ctdb/lib/tdb/common/lock.c index 140d17818c..c4a99b5719 100644 --- a/ctdb/lib/tdb/common/lock.c +++ b/ctdb/lib/tdb/common/lock.c @@ -288,7 +288,7 @@ int tdb_unlock(struct tdb_context *tdb, int list, int ltype) /* lock/unlock entire database */ -static int _tdb_lockall(struct tdb_context *tdb, int ltype) +static int _tdb_lockall(struct tdb_context *tdb, int ltype, int op) { /* There are no locks on read-only dbs */ if (tdb->read_only || tdb->traverse_read) @@ -309,9 +309,11 @@ static int _tdb_lockall(struct tdb_context *tdb, int ltype) return TDB_ERRCODE(TDB_ERR_LOCK, -1); } - if (tdb->methods->tdb_brlock(tdb, FREELIST_TOP, ltype, F_SETLKW, + if (tdb->methods->tdb_brlock(tdb, FREELIST_TOP, ltype, op, 0, 4*tdb->header.hash_size)) { - TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_lockall failed (%s)\n", strerror(errno))); + if (op == F_SETLKW) { + TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_lockall failed (%s)\n", strerror(errno))); + } return -1; } @@ -321,6 +323,8 @@ static int _tdb_lockall(struct tdb_context *tdb, int ltype) return 0; } + + /* unlock entire db */ static int _tdb_unlockall(struct tdb_context *tdb, int ltype) { @@ -353,7 +357,13 @@ static int _tdb_unlockall(struct tdb_context *tdb, int ltype) /* lock entire database with write lock */ int tdb_lockall(struct tdb_context *tdb) { - return _tdb_lockall(tdb, F_WRLCK); + return _tdb_lockall(tdb, F_WRLCK, F_SETLKW); +} + +/* lock entire database with write lock - nonblocking varient */ +int tdb_lockall_nonblock(struct tdb_context *tdb) +{ + return _tdb_lockall(tdb, F_WRLCK, F_SETLK); } /* unlock entire database with write lock */ @@ -365,7 +375,13 @@ int tdb_unlockall(struct tdb_context *tdb) /* lock entire database with read lock */ int tdb_lockall_read(struct tdb_context *tdb) { - return _tdb_lockall(tdb, F_RDLCK); + return _tdb_lockall(tdb, F_RDLCK, F_SETLKW); +} + +/* lock entire database with read lock - nonblock varient */ +int tdb_lockall_read_nonblock(struct tdb_context *tdb) +{ + return _tdb_lockall(tdb, F_RDLCK, F_SETLK); } /* unlock entire database with read lock */ diff --git a/ctdb/lib/tdb/include/tdb.h b/ctdb/lib/tdb/include/tdb.h index 36fc0b405a..30d88b8b88 100644 --- a/ctdb/lib/tdb/include/tdb.h +++ b/ctdb/lib/tdb/include/tdb.h @@ -116,8 +116,10 @@ int tdb_traverse(struct tdb_context *tdb, tdb_traverse_func fn, void *); int tdb_traverse_read(struct tdb_context *tdb, tdb_traverse_func fn, void *); int tdb_exists(struct tdb_context *tdb, TDB_DATA key); int tdb_lockall(struct tdb_context *tdb); +int tdb_lockall_nonblock(struct tdb_context *tdb); int tdb_unlockall(struct tdb_context *tdb); int tdb_lockall_read(struct tdb_context *tdb); +int tdb_lockall_read_nonblock(struct tdb_context *tdb); int tdb_unlockall_read(struct tdb_context *tdb); const char *tdb_name(struct tdb_context *tdb); int tdb_fd(struct tdb_context *tdb); |
