]> git.ozlabs.org Git - ccan/blobdiff - ccan/tdb2/tdb1_lock.c
tdb2: Make TDB1 use the same tdb_hash() wrapper as TDB2
[ccan] / ccan / tdb2 / tdb1_lock.c
index 2252e4791b91c9d8d2afb392b9fd3c87f86d9056..65fa1c123c5086b208448ee0dcb8487f1073d965 100644 (file)
@@ -180,7 +180,8 @@ int tdb1_lock(struct tdb1_context *tdb, int list, int ltype)
        int ret;
 
        ret = tdb1_lock_list(tdb, list, ltype, TDB_LOCK_WAIT);
-       if (ret) {
+       /* Don't log for EAGAIN and EINTR: they could have overridden lock fns */
+       if (ret && errno != EAGAIN && errno != EINTR) {
                tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR,
                           "tdb1_lock failed on list %d "
                           "ltype=%d (%s)",  list, ltype, strerror(errno));
@@ -391,25 +392,30 @@ int tdb1_unlockall_read(struct tdb1_context *tdb)
    contention - it cannot guarantee how many records will be locked */
 int tdb1_chainlock(struct tdb1_context *tdb, TDB_DATA key)
 {
-       int ret = tdb1_lock(tdb, TDB1_BUCKET(tdb->hash_fn(&key)), F_WRLCK);
+       int ret = tdb1_lock(tdb,
+                           TDB1_BUCKET(tdb_hash(tdb, key.dptr, key.dsize)),
+                           F_WRLCK);
        return ret;
 }
 
 int tdb1_chainunlock(struct tdb1_context *tdb, TDB_DATA key)
 {
-       return tdb1_unlock(tdb, TDB1_BUCKET(tdb->hash_fn(&key)), F_WRLCK);
+       return tdb1_unlock(tdb, TDB1_BUCKET(tdb_hash(tdb, key.dptr, key.dsize)),
+                          F_WRLCK);
 }
 
 int tdb1_chainlock_read(struct tdb1_context *tdb, TDB_DATA key)
 {
        int ret;
-       ret = tdb1_lock(tdb, TDB1_BUCKET(tdb->hash_fn(&key)), F_RDLCK);
+       ret = tdb1_lock(tdb, TDB1_BUCKET(tdb_hash(tdb, key.dptr, key.dsize)),
+                       F_RDLCK);
        return ret;
 }
 
 int tdb1_chainunlock_read(struct tdb1_context *tdb, TDB_DATA key)
 {
-       return tdb1_unlock(tdb, TDB1_BUCKET(tdb->hash_fn(&key)), F_RDLCK);
+       return tdb1_unlock(tdb, TDB1_BUCKET(tdb_hash(tdb, key.dptr, key.dsize)),
+                          F_RDLCK);
 }
 
 /* record lock stops delete underneath */