In many places we check whether locks are held: add a helper to do this.
The _tdb_lockall() case has already checked for the allrecord lock, so
the extra work done by tdb_have_extra_locks() is merely redundant.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
tdb->ecode = TDB_ERR_LOCK;
return -1;
}
tdb->ecode = TDB_ERR_LOCK;
return -1;
}
-
- if (tdb->num_locks != 0) {
+
+ if (tdb_have_extra_locks(tdb)) {
/* can't combine global and chain locks */
tdb->ecode = TDB_ERR_LOCK;
return -1;
/* can't combine global and chain locks */
tdb->ecode = TDB_ERR_LOCK;
return -1;
count++;
return (count == 1 ? tdb->methods->brunlock(tdb, F_RDLCK, off, 1) : 0);
}
count++;
return (count == 1 ? tdb->methods->brunlock(tdb, F_RDLCK, off, 1) : 0);
}
+
+bool tdb_have_extra_locks(struct tdb_context *tdb)
+{
+ if (tdb->allrecord_lock.count) {
+ return true;
+ }
+ if (tdb->num_lockrecs) {
+ return true;
+ }
+ return false;
+}
return 0; /* Nothing to do. */
}
return 0; /* Nothing to do. */
}
- if (tdb->num_locks != 0 || tdb->allrecord_lock.count) {
+ if (tdb_have_extra_locks(tdb)) {
TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_reopen: reopen not allowed with locks held\n"));
goto fail;
}
TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_reopen: reopen not allowed with locks held\n"));
goto fail;
}
enum tdb_lock_flags flags);
int tdb_brunlock(struct tdb_context *tdb,
int rw_type, tdb_off_t offset, size_t len);
enum tdb_lock_flags flags);
int tdb_brunlock(struct tdb_context *tdb,
int rw_type, tdb_off_t offset, size_t len);
+bool tdb_have_extra_locks(struct tdb_context *tdb);
int tdb_transaction_lock(struct tdb_context *tdb, int ltype);
int tdb_transaction_unlock(struct tdb_context *tdb, int ltype);
int tdb_brlock_upgrade(struct tdb_context *tdb, tdb_off_t offset, size_t len);
int tdb_transaction_lock(struct tdb_context *tdb, int ltype);
int tdb_transaction_unlock(struct tdb_context *tdb, int ltype);
int tdb_brlock_upgrade(struct tdb_context *tdb, tdb_off_t offset, size_t len);
- if (tdb->num_locks != 0 || tdb->allrecord_lock.count) {
+ if (tdb_have_extra_locks(tdb)) {
/* the caller must not have any locks when starting a
transaction as otherwise we'll be screwed by lack
of nested locks in posix */
/* the caller must not have any locks when starting a
transaction as otherwise we'll be screwed by lack
of nested locks in posix */
/* if there are any locks pending then the caller has not
nested their locks properly, so fail the transaction */
/* if there are any locks pending then the caller has not
nested their locks properly, so fail the transaction */
- if (tdb->num_locks || tdb->allrecord_lock.count) {
+ if (tdb_have_extra_locks(tdb)) {
tdb->ecode = TDB_ERR_LOCK;
TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_prepare_commit: locks pending on commit\n"));
_tdb_transaction_cancel(tdb, F_RDLCK);
tdb->ecode = TDB_ERR_LOCK;
TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_prepare_commit: locks pending on commit\n"));
_tdb_transaction_cancel(tdb, F_RDLCK);