]> git.ozlabs.org Git - ccan/commitdiff
tdb: cleanup: rename global_lock to allrecord_lock.
authorRusty Russell <rusty@rustcorp.com.au>
Mon, 22 Feb 2010 03:03:06 +0000 (13:33 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Mon, 22 Feb 2010 03:03:06 +0000 (13:33 +1030)
The word global is overloaded in tdb.  The global_lock inside struct
tdb_context is used to indicate we hold a lock across all the chains.

Rename it to allrecord_lock.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ccan/tdb/lock.c
ccan/tdb/open.c
ccan/tdb/tdb.c
ccan/tdb/tdb_private.h
ccan/tdb/transaction.c

index 515bffee598f01df50f73524d214b21b72f79510..6b320f45fedf7a410bbed3ba5a14eff9f1fc3599 100644 (file)
@@ -226,13 +226,13 @@ static int _tdb_lock(struct tdb_context *tdb, int list, int ltype,
        struct tdb_lock_type *new_lck;
        int i;
 
        struct tdb_lock_type *new_lck;
        int i;
 
-       /* a global lock allows us to avoid per chain locks */
-       if (tdb->global_lock.count && 
-           (ltype == tdb->global_lock.ltype || ltype == F_RDLCK)) {
+       /* a allrecord lock allows us to avoid per chain locks */
+       if (tdb->allrecord_lock.count &&
+           (ltype == tdb->allrecord_lock.ltype || ltype == F_RDLCK)) {
                return 0;
        }
 
                return 0;
        }
 
-       if (tdb->global_lock.count) {
+       if (tdb->allrecord_lock.count) {
                tdb->ecode = TDB_ERR_LOCK;
                return -1;
        }
                tdb->ecode = TDB_ERR_LOCK;
                return -1;
        }
@@ -318,12 +318,12 @@ static int _tdb_unlock(struct tdb_context *tdb, int list, int ltype,
        struct tdb_lock_type *lck = NULL;
 
        /* a global lock allows us to avoid per chain locks */
        struct tdb_lock_type *lck = NULL;
 
        /* a global lock allows us to avoid per chain locks */
-       if (tdb->global_lock.count && 
-           (ltype == tdb->global_lock.ltype || ltype == F_RDLCK)) {
+       if (tdb->allrecord_lock.count &&
+           (ltype == tdb->allrecord_lock.ltype || ltype == F_RDLCK)) {
                return 0;
        }
 
                return 0;
        }
 
-       if (tdb->global_lock.count) {
+       if (tdb->allrecord_lock.count) {
                tdb->ecode = TDB_ERR_LOCK;
                return -1;
        }
                tdb->ecode = TDB_ERR_LOCK;
                return -1;
        }
@@ -403,7 +403,7 @@ int tdb_unlock(struct tdb_context *tdb, int list, int ltype)
  */
 int tdb_transaction_lock(struct tdb_context *tdb, int ltype)
 {
  */
 int tdb_transaction_lock(struct tdb_context *tdb, int ltype)
 {
-       if (tdb->global_lock.count) {
+       if (tdb->allrecord_lock.count) {
                return 0;
        }
        if (tdb->transaction_lock_count > 0) {
                return 0;
        }
        if (tdb->transaction_lock_count > 0) {
@@ -426,7 +426,7 @@ int tdb_transaction_lock(struct tdb_context *tdb, int ltype)
 int tdb_transaction_unlock(struct tdb_context *tdb, int ltype)
 {
        int ret;
 int tdb_transaction_unlock(struct tdb_context *tdb, int ltype)
 {
        int ret;
-       if (tdb->global_lock.count) {
+       if (tdb->allrecord_lock.count) {
                return 0;
        }
        if (tdb->transaction_lock_count > 1) {
                return 0;
        }
        if (tdb->transaction_lock_count > 1) {
@@ -453,12 +453,12 @@ static int _tdb_lockall(struct tdb_context *tdb, int ltype,
                return -1;
        }
 
                return -1;
        }
 
-       if (tdb->global_lock.count && tdb->global_lock.ltype == ltype) {
-               tdb->global_lock.count++;
+       if (tdb->allrecord_lock.count && tdb->allrecord_lock.ltype == ltype) {
+               tdb->allrecord_lock.count++;
                return 0;
        }
 
                return 0;
        }
 
-       if (tdb->global_lock.count) {
+       if (tdb->allrecord_lock.count) {
                /* a global lock of a different type exists */
                tdb->ecode = TDB_ERR_LOCK;
                return -1;
                /* a global lock of a different type exists */
                tdb->ecode = TDB_ERR_LOCK;
                return -1;
@@ -479,8 +479,8 @@ static int _tdb_lockall(struct tdb_context *tdb, int ltype,
                return -1;
        }
 
                return -1;
        }
 
-       tdb->global_lock.count = 1;
-       tdb->global_lock.ltype = ltype;
+       tdb->allrecord_lock.count = 1;
+       tdb->allrecord_lock.ltype = ltype;
 
        return 0;
 }
 
        return 0;
 }
@@ -496,13 +496,13 @@ static int _tdb_unlockall(struct tdb_context *tdb, int ltype, bool mark_lock)
                return -1;
        }
 
                return -1;
        }
 
-       if (tdb->global_lock.ltype != ltype || tdb->global_lock.count == 0) {
+       if (tdb->allrecord_lock.ltype != ltype || tdb->allrecord_lock.count == 0) {
                tdb->ecode = TDB_ERR_LOCK;
                return -1;
        }
 
                tdb->ecode = TDB_ERR_LOCK;
                return -1;
        }
 
-       if (tdb->global_lock.count > 1) {
-               tdb->global_lock.count--;
+       if (tdb->allrecord_lock.count > 1) {
+               tdb->allrecord_lock.count--;
                return 0;
        }
 
                return 0;
        }
 
@@ -513,8 +513,8 @@ static int _tdb_unlockall(struct tdb_context *tdb, int ltype, bool mark_lock)
                return -1;
        }
 
                return -1;
        }
 
-       tdb->global_lock.count = 0;
-       tdb->global_lock.ltype = 0;
+       tdb->allrecord_lock.count = 0;
+       tdb->allrecord_lock.ltype = 0;
 
        return 0;
 }
 
        return 0;
 }
@@ -637,7 +637,7 @@ int tdb_chainunlock_read(struct tdb_context *tdb, TDB_DATA key)
 /* record lock stops delete underneath */
 int tdb_lock_record(struct tdb_context *tdb, tdb_off_t off)
 {
 /* record lock stops delete underneath */
 int tdb_lock_record(struct tdb_context *tdb, tdb_off_t off)
 {
-       if (tdb->global_lock.count) {
+       if (tdb->allrecord_lock.count) {
                return 0;
        }
        return off ? tdb->methods->brlock(tdb, F_RDLCK, off, 1, TDB_LOCK_WAIT) : 0;
                return 0;
        }
        return off ? tdb->methods->brlock(tdb, F_RDLCK, off, 1, TDB_LOCK_WAIT) : 0;
@@ -668,7 +668,7 @@ int tdb_unlock_record(struct tdb_context *tdb, tdb_off_t off)
        struct tdb_traverse_lock *i;
        uint32_t count = 0;
 
        struct tdb_traverse_lock *i;
        uint32_t count = 0;
 
-       if (tdb->global_lock.count) {
+       if (tdb->allrecord_lock.count) {
                return 0;
        }
 
                return 0;
        }
 
index 9a3457bc47555960ec0dce4b8665e3b242dfa446..d1a34bf1a2a47172fb4d534c134d0fb52aeeec29 100644 (file)
@@ -461,7 +461,7 @@ static int tdb_reopen_internal(struct tdb_context *tdb, bool active_lock)
                return 0; /* Nothing to do. */
        }
 
                return 0; /* Nothing to do. */
        }
 
-       if (tdb->num_locks != 0 || tdb->global_lock.count) {
+       if (tdb->num_locks != 0 || tdb->allrecord_lock.count) {
                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;
        }
index c6ce4548542cfc5222d7415fea952d0adff99519..2da4428230971f8602e9536d7a7af2abf69e404a 100644 (file)
@@ -805,7 +805,7 @@ static int tdb_free_region(struct tdb_context *tdb, tdb_off_t offset, ssize_t le
 
 /*
   wipe the entire database, deleting all records. This can be done
 
 /*
   wipe the entire database, deleting all records. This can be done
-  very fast by using a global lock. The entire data portion of the
+  very fast by using a allrecord lock. The entire data portion of the
   file becomes a single entry in the freelist.
 
   This code carefully steps around the recovery area, leaving it alone
   file becomes a single entry in the freelist.
 
   This code carefully steps around the recovery area, leaving it alone
index 975892ec2d1bfd6637153973955a207f14c4d741..b211662c4b867d05744703598e36e3d09f35be5b 100644 (file)
@@ -223,7 +223,7 @@ struct tdb_context {
        int read_only; /* opened read-only */
        int traverse_read; /* read-only traversal */
        int traverse_write; /* read-write traversal */
        int read_only; /* opened read-only */
        int traverse_read; /* read-only traversal */
        int traverse_write; /* read-write traversal */
-       struct tdb_lock_type global_lock;
+       struct tdb_lock_type allrecord_lock;
        int num_lockrecs;
        struct tdb_lock_type *lockrecs; /* only real locks, all with count>0 */
        enum TDB_ERROR ecode; /* error code for last tdb error */
        int num_lockrecs;
        struct tdb_lock_type *lockrecs; /* only real locks, all with count>0 */
        enum TDB_ERROR ecode; /* error code for last tdb error */
index ad07ad9fed1006dc41714c440395881ddc7465a3..f0871a6fdfdaf52630ec0c7f53f9262b90c54f05 100644 (file)
@@ -510,10 +510,10 @@ int _tdb_transaction_cancel(struct tdb_context *tdb, int ltype)
        }
 
        /* remove any global lock created during the transaction */
        }
 
        /* remove any global lock created during the transaction */
-       if (tdb->global_lock.count != 0) {
-               tdb_brunlock(tdb, tdb->global_lock.ltype,
+       if (tdb->allrecord_lock.count != 0) {
+               tdb_brunlock(tdb, tdb->allrecord_lock.ltype,
                             FREELIST_TOP, 4*tdb->header.hash_size);
                             FREELIST_TOP, 4*tdb->header.hash_size);
-               tdb->global_lock.count = 0;
+               tdb->allrecord_lock.count = 0;
        }
 
        /* remove any locks created during the transaction */
        }
 
        /* remove any locks created during the transaction */
@@ -564,7 +564,7 @@ int tdb_transaction_start(struct tdb_context *tdb)
                return 0;
        }
 
                return 0;
        }
 
-       if (tdb->num_locks != 0 || tdb->global_lock.count) {
+       if (tdb->num_locks != 0 || tdb->allrecord_lock.count) {
                /* 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 */
@@ -944,7 +944,7 @@ static int _tdb_transaction_prepare_commit(struct tdb_context *tdb)
        
        /* 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->global_lock.count) {
+       if (tdb->num_locks || tdb->allrecord_lock.count) {
                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);