]> git.ozlabs.org Git - ccan/blobdiff - ccan/tdb/open.c
tdb: use tdb_nest_lock() for open lock.
[ccan] / ccan / tdb / open.c
index 9a3457bc47555960ec0dce4b8665e3b242dfa446..54a8fe57ad11a460471785dbf370f7ae1f4a9b93 100644 (file)
@@ -240,7 +240,7 @@ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int tdb_flags,
         fcntl(tdb->fd, F_SETFD, v | FD_CLOEXEC);
 
        /* ensure there is only one process initialising at once */
-       if (tdb->methods->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_open_ex: failed to get open lock on %s: %s\n",
                         name, strerror(errno)));
                goto fail;      /* errno set by tdb_brlock */
@@ -356,8 +356,9 @@ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int tdb_flags,
        /* Internal (memory-only) databases skip all the code above to
         * do with disk files, and resume here by releasing their
         * open lock and hooking into the active list. */
-       if (tdb->methods->brunlock(tdb, F_WRLCK, OPEN_LOCK, 1) == -1)
+       if (tdb_nest_unlock(tdb, OPEN_LOCK, F_WRLCK, false) == -1) {
                goto fail;
+       }
        tdb->next = tdbs;
        tdbs = tdb;
        return tdb;
@@ -461,7 +462,7 @@ static int tdb_reopen_internal(struct tdb_context *tdb, bool active_lock)
                return 0; /* Nothing to do. */
        }
 
-       if (tdb->num_locks != 0 || tdb->global_lock.count) {
+       if (tdb_have_extra_locks(tdb)) {
                TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_reopen: reopen not allowed with locks held\n"));
                goto fail;
        }