tdb: rename tdb_release_extra_locks() to tdb_release_transaction_locks()
authorRusty Russell <rusty@rustcorp.com.au>
Thu, 22 Apr 2010 04:24:05 +0000 (13:54 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Thu, 22 Apr 2010 04:24:05 +0000 (13:54 +0930)
tdb_release_extra_locks() is too general: it carefully skips over the
transaction lock, even though the only caller then drops it.  Change
this, and rename it to show it's clearly transaction-specific.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
(Imported from commit a84222bbaf9ed2c7b9c61b8157b2e3c85f17fa32)

lib/tdb/common/lock.c
lib/tdb/common/tdb_private.h
lib/tdb/common/transaction.c

index 2a681efc9963afa9e2e3db7b7122f7e7beb3c65e..193d1d8a0aeef437c95ab4be9cd55b80cf1ea1b6 100644 (file)
@@ -719,11 +719,10 @@ bool tdb_have_extra_locks(struct tdb_context *tdb)
        return extra;
 }
 
-/* The transaction code uses this to remove all locks.  Note that this
-   may include OPEN_LOCK. */
-void tdb_release_extra_locks(struct tdb_context *tdb)
+/* The transaction code uses this to remove all locks. */
+void tdb_release_transaction_locks(struct tdb_context *tdb)
 {
-       unsigned int i, extra = 0;
+       unsigned int i, active = 0;
 
        if (tdb->allrecord_lock.count != 0) {
                tdb_brunlock(tdb, tdb->allrecord_lock.ltype, FREELIST_TOP, 0);
@@ -733,16 +732,14 @@ void tdb_release_extra_locks(struct tdb_context *tdb)
        for (i=0;i<tdb->num_lockrecs;i++) {
                struct tdb_lock_type *lck = &tdb->lockrecs[i];
 
-               /* Don't release transaction or active locks! */
-               if (tdb->transaction && lck->off == TRANSACTION_LOCK) {
-                       tdb->lockrecs[extra++] = *lck;
-               } else if (lck->off == ACTIVE_LOCK) {
-                       tdb->lockrecs[extra++] = *lck;
+               /* Don't release the active lock!  Copy it to first entry. */
+               if (lck->off == ACTIVE_LOCK) {
+                       tdb->lockrecs[active++] = *lck;
                } else {
                        tdb_brunlock(tdb, lck->ltype, lck->off, 1);
                }
        }
-       tdb->num_lockrecs = extra;
+       tdb->num_lockrecs = active;
        if (tdb->num_lockrecs == 0) {
                SAFE_FREE(tdb->lockrecs);
        }
index 013c2f022e45befdc49891a3bd3b4ebe3bcbef3b..b031ddd324a13a1e3d8fff65e31291cc1bddf838 100644 (file)
@@ -233,7 +233,7 @@ int tdb_brlock(struct tdb_context *tdb,
 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);
-void tdb_release_extra_locks(struct tdb_context *tdb);
+void tdb_release_transaction_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_allrecord_lock(struct tdb_context *tdb, int ltype,
index 0f9f80c86e0f59bb6860da3e36cac7e01f3db61a..d24256d2fbadd196020a1b7ad83975b42f5579de 100644 (file)
@@ -615,12 +615,11 @@ static int _tdb_transaction_cancel(struct tdb_context *tdb)
        }
 
        /* This also removes the OPEN_LOCK, if we have it. */
-       tdb_release_extra_locks(tdb);
+       tdb_release_transaction_locks(tdb);
 
        /* restore the normal io methods */
        tdb->methods = tdb->transaction->io_methods;
 
-       tdb_transaction_unlock(tdb, F_WRLCK);
        SAFE_FREE(tdb->transaction->hash_heads);
        SAFE_FREE(tdb->transaction);