]> git.ozlabs.org Git - ccan-lca-2011.git/blobdiff - ccan/tdb2/free.c
tdb2: relax locking to allow two free list locks at once
[ccan-lca-2011.git] / ccan / tdb2 / free.c
index 8ff5d74a3fd7a8a400b243b9dd8a22c1dfe44af6..a854aadfb6a3b25f763062ba8acea18a20a5d7f1 100644 (file)
@@ -450,15 +450,17 @@ again:
                if (tdb_write_convert(tdb, best_off, &rec, sizeof(rec)) != 0)
                        goto unlock_err;
 
-               tdb_unlock_free_bucket(tdb, b_off);
-
+               /* Bucket of leftover will be <= current bucket, so nested
+                * locking is allowed. */
                if (leftover) {
                        if (add_free_record(tdb,
                                            best_off + sizeof(rec)
                                            + frec_len(&best) - leftover,
                                            leftover))
-                               return TDB_OFF_ERR;
+                               best_off = TDB_OFF_ERR;
                }
+               tdb_unlock_free_bucket(tdb, b_off);
+
                return best_off;
        }