X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftdb%2Ftransaction.c;h=ded3fa836fc721a07932c54a6f741b89c8329066;hp=04e4bbcd2e574820cf2edbde0e0c2233a2952960;hb=e9989ef0758b3b660abf444d014c5b51a3a7c1b4;hpb=d92b8a7d9a050eb9735e48a8d37a5833500242d3 diff --git a/ccan/tdb/transaction.c b/ccan/tdb/transaction.c index 04e4bbcd..ded3fa83 100644 --- a/ccan/tdb/transaction.c +++ b/ccan/tdb/transaction.c @@ -135,9 +135,6 @@ struct tdb_transaction { bool prepared; tdb_off_t magic_offset; - /* set when the OPEN_LOCK has been taken */ - bool open_lock_taken; - /* old file size before transaction */ tdb_len_t old_map_size; @@ -418,6 +415,9 @@ static int transaction_brlock(struct tdb_context *tdb, int rw_type, tdb_off_t offset, size_t len, enum tdb_lock_flags flags) { + /* FIXME: We actually grab the open lock during a transaction. */ + if (offset == OPEN_LOCK) + return tdb_brlock(tdb, rw_type, offset, len, flags); return 0; } @@ -504,28 +504,8 @@ int _tdb_transaction_cancel(struct tdb_context *tdb, int ltype) } } - if (tdb->transaction->open_lock_taken) { - tdb_brunlock(tdb, F_WRLCK, OPEN_LOCK, 1); - tdb->transaction->open_lock_taken = false; - } - - /* remove any global lock created during the transaction */ - if (tdb->allrecord_lock.count != 0) { - tdb_brunlock(tdb, tdb->allrecord_lock.ltype, - FREELIST_TOP, 4*tdb->header.hash_size); - tdb->allrecord_lock.count = 0; - } - - /* remove any locks created during the transaction */ - if (tdb->num_locks != 0) { - for (i=0;inum_lockrecs;i++) { - tdb_brunlock(tdb, tdb->lockrecs[i].ltype, - tdb->lockrecs[i].off, 1); - } - tdb->num_locks = 0; - tdb->num_lockrecs = 0; - SAFE_FREE(tdb->lockrecs); - } + /* This also removes the OPEN_LOCK, if we have it. */ + tdb_release_extra_locks(tdb); /* restore the normal io methods */ tdb->methods = tdb->transaction->io_methods; @@ -961,15 +941,12 @@ static int _tdb_transaction_prepare_commit(struct tdb_context *tdb) /* get the open lock - this prevents new users attaching to the database during the commit */ - if (tdb_brlock(tdb, F_WRLCK, OPEN_LOCK, 1, TDB_LOCK_WAIT) == -1) { + if (tdb_nest_lock(tdb, OPEN_LOCK, F_WRLCK, TDB_LOCK_WAIT) == -1) { TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_prepare_commit: failed to get open lock\n")); - tdb->ecode = TDB_ERR_LOCK; _tdb_transaction_cancel(tdb, F_WRLCK); return -1; } - tdb->transaction->open_lock_taken = true; - if (!(tdb->flags & TDB_NOSYNC)) { /* write the recovery data to the end of the file */ if (transaction_setup_recovery(tdb, &tdb->transaction->magic_offset) == -1) {