]> git.ozlabs.org Git - ccan/blobdiff - ccan/tdb2/open.c
htable, strset: benchmarking tools.
[ccan] / ccan / tdb2 / open.c
index 3217a9b252ad7be2670733fc7b1930339f5b6968..dad353480fffe872cc82a90f0a773e566e604aba 100644 (file)
@@ -388,6 +388,7 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags,
        struct tdb_header hdr;
        struct tdb_attribute_seed *seed = NULL;
        struct tdb_attribute_tdb1_hashsize *hsize_attr = NULL;
+       struct tdb_attribute_tdb1_max_dead *maxsize_attr = NULL;
        tdb_bool_err berr;
        enum TDB_ERROR ecode;
        int openlock;
@@ -433,6 +434,9 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags,
                case TDB_ATTRIBUTE_TDB1_HASHSIZE:
                        hsize_attr = &attr->tdb1_hashsize;
                        break;
+               case TDB_ATTRIBUTE_TDB1_MAX_DEAD:
+                       maxsize_attr = &attr->tdb1_max_dead;
+                       break;
                default:
                        /* These are set as normal. */
                        ecode = tdb_set_attribute(tdb, attr);
@@ -511,7 +515,7 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags,
                }
                tdb->file->fd = -1;
                if (tdb->flags & TDB_VERSION1)
-                       ecode = tdb1_new_database(tdb, hsize_attr);
+                       ecode = tdb1_new_database(tdb, hsize_attr, maxsize_attr);
                else {
                        ecode = tdb_new_database(tdb, seed, &hdr);
                        if (ecode == TDB_SUCCESS) {
@@ -591,7 +595,7 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags,
        rlen = pread(tdb->file->fd, &hdr, sizeof(hdr), 0);
        if (rlen == 0 && (open_flags & O_CREAT)) {
                if (tdb->flags & TDB_VERSION1) {
-                       ecode = tdb1_new_database(tdb, hsize_attr);
+                       ecode = tdb1_new_database(tdb, hsize_attr, maxsize_attr);
                        if (ecode != TDB_SUCCESS)
                                goto fail;
                        goto finished;
@@ -608,7 +612,7 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags,
        } else if (rlen < sizeof(hdr)
                   || strcmp(hdr.magic_food, TDB_MAGIC_FOOD) != 0) {
                if (is_tdb1(&tdb->tdb1.header, &hdr, rlen)) {
-                       ecode = tdb1_open(tdb);
+                       ecode = tdb1_open(tdb, maxsize_attr);
                        if (!ecode)
                                goto finished;
                        goto fail;
@@ -623,7 +627,7 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags,
                        tdb->flags |= TDB_CONVERT;
                else {
                        if (is_tdb1(&tdb->tdb1.header, &hdr, rlen)) {
-                               ecode = tdb1_open(tdb);
+                               ecode = tdb1_open(tdb, maxsize_attr);
                                if (!ecode)
                                        goto finished;
                                goto fail;
@@ -702,7 +706,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);
@@ -723,18 +727,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: