]> git.ozlabs.org Git - ccan/blobdiff - ccan/tdb2/transaction.c
tdb2: rework free.c functions to return enum TDB_ERROR.
[ccan] / ccan / tdb2 / transaction.c
index e7050bfe1ec96555ce6907d1a5c00e7441ca509a..604861b738e75e9c7efab447f7d26d19780a5ffc 100644 (file)
@@ -642,8 +642,8 @@ static int tdb_recovery_allocate(struct tdb_context *tdb,
        enum TDB_ERROR ecode;
 
        recovery_head = tdb_read_off(tdb, offsetof(struct tdb_header,recovery));
-       if (recovery_head == TDB_OFF_ERR) {
-               tdb_logerr(tdb, tdb->ecode, TDB_LOG_ERROR,
+       if (TDB_OFF_IS_ERR(recovery_head)) {
+               tdb_logerr(tdb, recovery_head, TDB_LOG_ERROR,
                         "tdb_recovery_allocate:"
                         " failed to read recovery head");
                return -1;
@@ -681,9 +681,10 @@ static int tdb_recovery_allocate(struct tdb_context *tdb,
           the transaction) */
        if (recovery_head != 0) {
                add_stat(tdb, frees, 1);
-               if (add_free_record(tdb, recovery_head,
-                                   sizeof(rec) + rec.max_len) != 0) {
-                       tdb_logerr(tdb, tdb->ecode, TDB_LOG_ERROR,
+               ecode = add_free_record(tdb, recovery_head,
+                                       sizeof(rec) + rec.max_len);
+               if (ecode != TDB_SUCCESS) {
+                       tdb_logerr(tdb, ecode, TDB_LOG_ERROR,
                                   "tdb_recovery_allocate:"
                                   " failed to free previous recovery area");
                        return -1;
@@ -1108,8 +1109,8 @@ int tdb_transaction_recover(struct tdb_context *tdb)
 
        /* find the recovery area */
        recovery_head = tdb_read_off(tdb, offsetof(struct tdb_header,recovery));
-       if (recovery_head == TDB_OFF_ERR) {
-               tdb_logerr(tdb, tdb->ecode, TDB_LOG_ERROR,
+       if (TDB_OFF_IS_ERR(recovery_head)) {
+               tdb_logerr(tdb, recovery_head, TDB_LOG_ERROR,
                         "tdb_transaction_recover:"
                         " failed to read recovery head");
                return -1;
@@ -1241,7 +1242,8 @@ bool tdb_needs_recovery(struct tdb_context *tdb)
 
        /* find the recovery area */
        recovery_head = tdb_read_off(tdb, offsetof(struct tdb_header,recovery));
-       if (recovery_head == TDB_OFF_ERR) {
+       if (TDB_OFF_IS_ERR(recovery_head)) {
+               tdb->ecode = recovery_head;
                return true;
        }