]> git.ozlabs.org Git - ccan/blobdiff - ccan/tdb2/open.c
tdb2: don't be fascist when TDB_VERSION1 is specified.
[ccan] / ccan / tdb2 / open.c
index 3e3b083e59d788906169b3fc0dcaf5ae9d9a3571..3c6abe726e6e58f2404800922055ff4a690fe68d 100644 (file)
@@ -647,12 +647,9 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags,
                goto fail;
        }
 
+       /* This is a version2 tdb. */
        if (tdb->flags & TDB_VERSION1) {
-               ecode = tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR,
-                                  "tdb_open:"
-                                  " %s does not need TDB_VERSION1",
-                                  name);
-               goto fail;
+               tdb->flags &= ~TDB_VERSION1;
        }
 
        tdb2_context_init(tdb);
@@ -706,7 +703,7 @@ finished:
                berr = tdb_needs_recovery(tdb);
                if (unlikely(berr != false)) {
                        if (berr < 0) {
-                               ecode = berr;
+                               ecode = TDB_OFF_TO_ERR(berr);
                                goto fail;
                        }
                        ecode = tdb_lock_and_recover(tdb);
@@ -727,18 +724,18 @@ finished:
 
  fail:
        /* Map ecode to some logical errno. */
-       switch (ecode) {
-       case TDB_ERR_CORRUPT:
-       case TDB_ERR_IO:
+       switch (TDB_ERR_TO_OFF(ecode)) {
+       case TDB_ERR_TO_OFF(TDB_ERR_CORRUPT):
+       case TDB_ERR_TO_OFF(TDB_ERR_IO):
                saved_errno = EIO;
                break;
-       case TDB_ERR_LOCK:
+       case TDB_ERR_TO_OFF(TDB_ERR_LOCK):
                saved_errno = EWOULDBLOCK;
                break;
-       case TDB_ERR_OOM:
+       case TDB_ERR_TO_OFF(TDB_ERR_OOM):
                saved_errno = ENOMEM;
                break;
-       case TDB_ERR_EINVAL:
+       case TDB_ERR_TO_OFF(TDB_ERR_EINVAL):
                saved_errno = EINVAL;
                break;
        default: