#include <ccan/build_assert/build_assert.h>
/* If we were threaded, we could wait for unlock, but we're not, so fail. */
-static enum TDB_ERROR owner_conflict(struct tdb_context *tdb, const char *call)
+enum TDB_ERROR owner_conflict(struct tdb_context *tdb, const char *call)
{
return tdb_logerr(tdb, TDB_ERR_LOCK, TDB_LOG_USE_ERROR,
"%s: lock owned by another tdb in this process.",
}
/* If we fork, we no longer really own locks. */
-static bool check_lock_pid(struct tdb_context *tdb,
- const char *call, bool log)
+bool check_lock_pid(struct tdb_context *tdb, const char *call, bool log)
{
/* No locks? No problem! */
if (tdb->file->allrecord_lock.count == 0
tdb_brunlock(tdb, ltype, offset, 1);
if (berr < 0)
- return berr;
+ return TDB_OFF_TO_ERR(berr);
ecode = tdb_lock_and_recover(tdb);
if (ecode == TDB_SUCCESS) {
ecode = tdb_brlock(tdb, ltype, offset, 1,
enum TDB_ERROR ecode;
tdb_bool_err berr;
+ if (tdb->flags & TDB_VERSION1) {
+ if (tdb1_allrecord_lock(tdb, ltype, flags, upgradable) == -1)
+ return tdb->last_error;
+ return TDB_SUCCESS;
+ }
+
if (tdb->flags & TDB_NOLOCK)
return TDB_SUCCESS;
tdb_allrecord_unlock(tdb, ltype);
if (berr < 0)
- return berr;
+ return TDB_OFF_TO_ERR(berr);
ecode = tdb_lock_and_recover(tdb);
if (ecode != TDB_SUCCESS) {
return ecode;
/* unlock entire db */
void tdb_allrecord_unlock(struct tdb_context *tdb, int ltype)
{
+ if (tdb->flags & TDB_VERSION1) {
+ tdb1_allrecord_unlock(tdb, ltype);
+ return;
+ }
+
if (tdb->flags & TDB_NOLOCK)
return;
return tdb_logerr(tdb, TDB_ERR_LOCK, TDB_LOG_ERROR,
"tdb_unlock_hashes RO allrecord!");
}
+ if (tdb->file->allrecord_lock.owner != tdb) {
+ return tdb_logerr(tdb, TDB_ERR_LOCK, TDB_LOG_USE_ERROR,
+ "tdb_unlock_hashes:"
+ " not locked by us!");
+ }
return TDB_SUCCESS;
}
if (!check_lock_pid(tdb, "tdb_lock_free_bucket", true))
return TDB_ERR_LOCK;
+ if (tdb->file->allrecord_lock.owner != tdb) {
+ return owner_conflict(tdb, "tdb_lock_free_bucket");
+ }
+
if (tdb->file->allrecord_lock.ltype == F_WRLCK)
return 0;
return tdb_logerr(tdb, TDB_ERR_LOCK, TDB_LOG_ERROR,
while (tdb->file->allrecord_lock.count
&& tdb->file->allrecord_lock.owner == tdb) {
- if (tdb->flags & TDB_VERSION1)
- tdb1_allrecord_unlock(tdb,
- tdb->file->allrecord_lock.ltype);
- else
- tdb_allrecord_unlock(tdb,
- tdb->file->allrecord_lock.ltype);
+ tdb_allrecord_unlock(tdb, tdb->file->allrecord_lock.ltype);
}
for (i=0; i<tdb->file->num_lockrecs; i++) {