X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftdb%2Ftransaction.c;h=11194773647e255f1a7c8743cd69d5c85bfeda59;hp=238034f3700687a77e347b71f456e121485333b1;hb=729fc5b931c8eb26f192399d8aa7064f9af058df;hpb=8321967a3b0917b9b1ac4cbc3cda2ace881a886f diff --git a/ccan/tdb/transaction.c b/ccan/tdb/transaction.c index 238034f3..11194773 100644 --- a/ccan/tdb/transaction.c +++ b/ccan/tdb/transaction.c @@ -408,33 +408,12 @@ static int transaction_expand_file(struct tdb_context *tdb, tdb_off_t size, return 0; } -/* - brlock during a transaction - ignore them -*/ -static int transaction_brlock(struct tdb_context *tdb, - int rw_type, tdb_off_t offset, size_t len, - enum tdb_lock_flags flags) -{ - /* FIXME: We actually grab the open lock during a transaction. */ - if (offset == OPEN_LOCK) - return tdb_brlock(tdb, rw_type, offset, len, flags); - return 0; -} - -static int transaction_brunlock(struct tdb_context *tdb, - int rw_type, tdb_off_t offset, size_t len) -{ - return 0; -} - static const struct tdb_methods transaction_methods = { transaction_read, transaction_write, transaction_next_hash_chain, transaction_oob, transaction_expand_file, - transaction_brlock, - transaction_brunlock }; /* @@ -1203,16 +1182,6 @@ int tdb_transaction_recover(struct tdb_context *tdb) return -1; } - /* reduce the file size to the old size */ - tdb_munmap(tdb); - if (ftruncate(tdb->fd, recovery_eof) != 0) { - TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_recover: failed to reduce to recovery size\n")); - tdb->ecode = TDB_ERR_IO; - return -1; - } - tdb->map_size = recovery_eof; - tdb_mmap(tdb); - if (transaction_sync(tdb, 0, recovery_eof) == -1) { TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_recover: failed to sync2 recovery\n")); tdb->ecode = TDB_ERR_IO; @@ -1225,3 +1194,28 @@ int tdb_transaction_recover(struct tdb_context *tdb) /* all done */ return 0; } + +/* Any I/O failures we say "needs recovery". */ +bool tdb_needs_recovery(struct tdb_context *tdb) +{ + tdb_off_t recovery_head; + struct tdb_record rec; + + /* find the recovery area */ + if (tdb_ofs_read(tdb, TDB_RECOVERY_HEAD, &recovery_head) == -1) { + return true; + } + + if (recovery_head == 0) { + /* we have never allocated a recovery record */ + return false; + } + + /* read the recovery record */ + if (tdb->methods->tdb_read(tdb, recovery_head, &rec, + sizeof(rec), DOCONV()) == -1) { + return true; + } + + return (rec.magic == TDB_RECOVERY_MAGIC); +}