*/
int tdb_transaction_start(struct tdb_context *tdb)
{
+ enum TDB_ERROR ecode;
+
/* some sanity checks */
if (tdb->read_only || (tdb->flags & TDB_INTERNAL)) {
tdb_logerr(tdb, TDB_ERR_EINVAL, TDB_LOG_USE_ERROR,
/* cope with nested tdb_transaction_start() calls */
if (tdb->transaction != NULL) {
- tdb_logerr(tdb, TDB_ERR_NESTING, TDB_LOG_USE_ERROR,
+ tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_USE_ERROR,
"tdb_transaction_start:"
" already inside transaction");
return -1;
/* get the transaction write lock. This is a blocking lock. As
discussed with Volker, there are a number of ways we could
make this async, which we will probably do in the future */
- if (tdb_transaction_lock(tdb, F_WRLCK) == -1) {
+ ecode = tdb_transaction_lock(tdb, F_WRLCK);
+ if (ecode != TDB_SUCCESS) {
+ tdb->ecode = ecode;
SAFE_FREE(tdb->transaction->blocks);
SAFE_FREE(tdb->transaction);
return -1;
/* get a read lock over entire file. This is upgraded to a write
lock during the commit */
- if (tdb_allrecord_lock(tdb, F_RDLCK, TDB_LOCK_WAIT, true) == -1) {
+ ecode = tdb_allrecord_lock(tdb, F_RDLCK, TDB_LOCK_WAIT, true);
+ if (ecode != TDB_SUCCESS) {
+ tdb->ecode = ecode;
goto fail_allrecord_lock;
}
static int _tdb_transaction_prepare_commit(struct tdb_context *tdb)
{
const struct tdb_methods *methods;
+ enum TDB_ERROR ecode;
if (tdb->transaction == NULL) {
tdb_logerr(tdb, TDB_ERR_EINVAL, TDB_LOG_USE_ERROR,
methods = tdb->transaction->io_methods;
/* upgrade the main transaction lock region to a write lock */
- if (tdb_allrecord_upgrade(tdb) == -1) {
- tdb_logerr(tdb, tdb->ecode, TDB_LOG_ERROR,
+ ecode = tdb_allrecord_upgrade(tdb);
+ if (ecode != TDB_SUCCESS) {
+ tdb_logerr(tdb, ecode, TDB_LOG_ERROR,
"tdb_transaction_prepare_commit:"
" failed to upgrade hash locks");
_tdb_transaction_cancel(tdb);
/* get the open lock - this prevents new users attaching to the database
during the commit */
- if (tdb_lock_open(tdb, TDB_LOCK_WAIT|TDB_LOCK_NOCHECK) == -1) {
- tdb_logerr(tdb, tdb->ecode, TDB_LOG_ERROR,
- "tdb_transaction_prepare_commit:"
- " failed to get open lock");
+ ecode = tdb_lock_open(tdb, TDB_LOCK_WAIT|TDB_LOCK_NOCHECK);
+ if (ecode != TDB_SUCCESS) {
+ tdb_logerr(tdb, ecode, TDB_LOG_ERROR,
+ "tdb_transaction_prepare_commit:"
+ " failed to get open lock");
_tdb_transaction_cancel(tdb);
return -1;
}
tdb_trace(tdb, "tdb_transaction_commit");
- if (tdb->transaction->transaction_error) {
- tdb_transaction_cancel(tdb);
- tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR,
- "tdb_transaction_commit:"
- " transaction error pending");
- return -1;
- }
-
-
if (tdb->transaction->nesting != 0) {
tdb->transaction->nesting--;
return 0;