X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftdb%2Ftransaction.c;h=11194773647e255f1a7c8743cd69d5c85bfeda59;hp=9cbbcc9087fe1d441c4a829b7c121d560d57146a;hb=729fc5b931c8eb26f192399d8aa7064f9af058df;hpb=497e23b21fe7dc8256c23f79f14cdb4c3e86cc9e diff --git a/ccan/tdb/transaction.c b/ccan/tdb/transaction.c index 9cbbcc90..11194773 100644 --- a/ccan/tdb/transaction.c +++ b/ccan/tdb/transaction.c @@ -1194,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); +}