X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftdb2%2Ftdb.c;h=8bae9fc298516738f3e896aa4c31edfa7350f893;hp=cffb4130677a0cadcfe0f154e39207ab66ce1565;hb=d95645d52cea0c68cddfd72d21246394596d87e1;hpb=ef9dec6018e1f0c6e546245a1478be523592d02d diff --git a/ccan/tdb2/tdb.c b/ccan/tdb2/tdb.c index cffb4130..8bae9fc2 100644 --- a/ccan/tdb2/tdb.c +++ b/ccan/tdb2/tdb.c @@ -103,6 +103,7 @@ static int tdb_new_database(struct tdb_context *tdb, sizeof(newdb.hdr.hash_test), newdb.hdr.hash_seed, tdb->hash_priv); + newdb.hdr.recovery = 0; memset(newdb.hdr.reserved, 0, sizeof(newdb.hdr.reserved)); /* Initial hashes are empty. */ memset(newdb.hdr.hashtable, 0, sizeof(newdb.hdr.hashtable)); @@ -246,7 +247,7 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags, fcntl(tdb->fd, F_SETFD, v | FD_CLOEXEC); /* ensure there is only one process initialising at once */ - if (tdb_lock_open(tdb) == -1) { + if (tdb_lock_open(tdb, TDB_LOCK_WAIT|TDB_LOCK_NOCHECK) == -1) { tdb->log(tdb, TDB_DEBUG_ERROR, tdb->log_priv, "tdb_open: failed to get open lock on %s: %s\n", name, strerror(errno)); @@ -314,6 +315,12 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags, /* This make sure we have current map_size and mmap. */ tdb->methods->oob(tdb, tdb->map_size + 1, true); + /* Now it's fully formed, recover if necessary. */ + if (tdb_needs_recovery(tdb) && tdb_lock_and_recover(tdb) == -1) { + errno = EIO; + goto fail; + } + if (tdb_flist_init(tdb) == -1) goto fail; @@ -595,12 +602,11 @@ int tdb_close(struct tdb_context *tdb) struct tdb_context **i; int ret = 0; - /* FIXME: + tdb_trace(tdb, "tdb_close"); + if (tdb->transaction) { tdb_transaction_cancel(tdb); } - */ - tdb_trace(tdb, "tdb_close"); if (tdb->map_ptr) { if (tdb->flags & TDB_INTERNAL)