]> git.ozlabs.org Git - ccan/commitdiff
tdb2: add tdb_attribute_tdb1_max_dead
authorRusty Russell <rusty@rustcorp.com.au>
Wed, 31 Aug 2011 06:01:07 +0000 (15:31 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Wed, 31 Aug 2011 06:01:07 +0000 (15:31 +0930)
This allows us to simulate the old "volatile" flag for tdb1.  It's not
necessary for tdb2.

As this is the last function in tdb1.h, we remove that file.

ccan/tdb2/open.c
ccan/tdb2/private.h
ccan/tdb2/tdb1.h [deleted file]
ccan/tdb2/tdb1_open.c
ccan/tdb2/tdb1_private.h
ccan/tdb2/tdb2.h
ccan/tdb2/test/failtest_helper.h
ccan/tdb2/test/tdb1-external-agent.c

index 3217a9b252ad7be2670733fc7b1930339f5b6968..3e3b083e59d788906169b3fc0dcaf5ae9d9a3571 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;
index b801ffaf828f54b112a0116c436666e20da73461..30338d77abb51deee0e761307e01af588b035725 100644 (file)
@@ -639,8 +639,10 @@ int tdb1_check(struct tdb_context *tdb,
 
 /* tdb1_open.c: */
 int tdb1_new_database(struct tdb_context *tdb,
-                     struct tdb_attribute_tdb1_hashsize *hashsize);
-enum TDB_ERROR tdb1_open(struct tdb_context *tdb);
+                     struct tdb_attribute_tdb1_hashsize *hashsize,
+                     struct tdb_attribute_tdb1_max_dead *max_dead);
+enum TDB_ERROR tdb1_open(struct tdb_context *tdb,
+                        struct tdb_attribute_tdb1_max_dead *max_dead);
 
 /* tdb1_io.c: */
 enum TDB_ERROR tdb1_probe_length(struct tdb_context *tdb);
diff --git a/ccan/tdb2/tdb1.h b/ccan/tdb2/tdb1.h
deleted file mode 100644 (file)
index c46abc7..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-#ifndef TDB1_H
-#define TDB1_H
-
-/*
-   Unix SMB/CIFS implementation.
-
-   trivial database library (version 1 compat functions)
-
-   Copyright (C) Andrew Tridgell 1999-2004
-   Copyright (C) Rusty Russell 2011
-
-     ** NOTE! The following LGPL license applies to the tdb
-     ** library. This does NOT imply that all of Samba is released
-     ** under the LGPL
-
-   This library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 3 of the License, or (at your option) any later version.
-
-   This library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with this library; if not, see <http://www.gnu.org/licenses/>.
-*/
-#include "tdb2.h"
-
-#ifndef _SAMBA_BUILD_
-/* For mode_t */
-#include <sys/types.h>
-/* For O_* flags. */
-#include <sys/stat.h>
-#endif
-
-
-void tdb1_set_max_dead(struct tdb_context *tdb, int max_dead);
-
-/* @} ******************************************************************/
-
-#endif /* tdb1.h */
index df46450c90b1d3596bf6dd84624b5b9ac80751c3..e22a6d1428b157b17052d4e80c1962ce314f5755 100644 (file)
@@ -42,7 +42,8 @@ void tdb1_header_hash(struct tdb_context *tdb,
                *magic1_hash = 1;
 }
 
-static void tdb_context_init(struct tdb_context *tdb)
+static void tdb_context_init(struct tdb_context *tdb,
+                            struct tdb_attribute_tdb1_max_dead *max_dead)
 {
        assert(tdb->flags & TDB_VERSION1);
 
@@ -58,20 +59,24 @@ static void tdb_context_init(struct tdb_context *tdb)
                tdb->tdb1.page_size = 0x2000;
        }
 
-       /* FIXME: Used to be 5 for TDB_VOLATILE. */
-       tdb->tdb1.max_dead_records = 0;
+       if (max_dead) {
+               tdb->tdb1.max_dead_records = max_dead->max_dead;
+       } else {
+               tdb->tdb1.max_dead_records = 0;
+       }
 }
 
 /* initialise a new database */
 enum TDB_ERROR tdb1_new_database(struct tdb_context *tdb,
-                                struct tdb_attribute_tdb1_hashsize *hashsize)
+                                struct tdb_attribute_tdb1_hashsize *hashsize,
+                                struct tdb_attribute_tdb1_max_dead *max_dead)
 {
        struct tdb1_header *newdb;
        size_t size;
        int hash_size = TDB1_DEFAULT_HASH_SIZE;
        enum TDB_ERROR ret = TDB_ERR_IO;
 
-       tdb_context_init(tdb);
+       tdb_context_init(tdb, max_dead);
 
        /* Default TDB2 hash becomes default TDB1 hash. */
        if (tdb->hash_fn == tdb_jenkins_hash)
@@ -164,14 +169,15 @@ static bool check_header_hash(struct tdb_context *tdb,
 }
 
 /* We are hold the TDB open lock on tdb->fd. */
-enum TDB_ERROR tdb1_open(struct tdb_context *tdb)
+enum TDB_ERROR tdb1_open(struct tdb_context *tdb,
+                        struct tdb_attribute_tdb1_max_dead *max_dead)
 {
        const char *hash_alg;
        uint32_t magic1, magic2;
 
        tdb->flags |= TDB_VERSION1;
 
-       tdb_context_init(tdb);
+       tdb_context_init(tdb, max_dead);
 
        /* Default TDB2 hash becomes default TDB1 hash. */
        if (tdb->hash_fn == tdb_jenkins_hash) {
@@ -216,12 +222,3 @@ enum TDB_ERROR tdb1_open(struct tdb_context *tdb)
        }
        return TDB_SUCCESS;
 }
-
-/*
- * Set the maximum number of dead records per hash chain
- */
-
-void tdb1_set_max_dead(struct tdb_context *tdb, int max_dead)
-{
-       tdb->tdb1.max_dead_records = max_dead;
-}
index 5d27c785fcf947d9f4de4ca7609905de5ae179c6..ea147a89676974d69ba955f146e7a3b84cbf0e5b 100644 (file)
@@ -26,7 +26,6 @@
 */
 
 #include "private.h"
-#include "tdb1.h"
 
 #include <limits.h>
 
index be5d50027712d4cf511ce60b02ae5e95bfc850e1..525fbd71758c5c0632c101729dce761295b3cb66 100644 (file)
@@ -631,6 +631,7 @@ enum tdb_attribute_type {
        TDB_ATTRIBUTE_OPENHOOK = 4,
        TDB_ATTRIBUTE_FLOCK = 5,
        TDB_ATTRIBUTE_TDB1_HASHSIZE = 128,
+       TDB_ATTRIBUTE_TDB1_MAX_DEAD = 129,
 };
 
 /**
@@ -875,6 +876,19 @@ struct tdb_attribute_tdb1_hashsize {
        unsigned int hsize;
 };
 
+/**
+ * struct tdb_attribute_tdb1_max_dead - tdb1 number of maximum dead records.
+ *
+ * TDB1 has a method to speed up its slow free list: it lets a certain
+ * number of "dead" records build up before freeing them.  This is
+ * particularly useful for volatile TDBs; setting it to 5 is
+ * equivalent to tdb1's TDB_VOLATILE flag.
+ */
+struct tdb_attribute_tdb1_max_dead {
+       struct tdb_attribute_base base; /* .attr = TDB_ATTRIBUTE_TDB1_MAX_DEAD */
+       unsigned int max_dead;
+};
+
 /**
  * union tdb_attribute - tdb attributes.
  *
@@ -894,6 +908,7 @@ union tdb_attribute {
        struct tdb_attribute_openhook openhook;
        struct tdb_attribute_flock flock;
        struct tdb_attribute_tdb1_hashsize tdb1_hashsize;
+       struct tdb_attribute_tdb1_max_dead tdb1_max_dead;
 };
 
 #ifdef  __cplusplus
index 54529fe89333ef2915a2438924af255f6b7e4fd2..02acac8c3cf493a0bd64316651cefb25d810f78b 100644 (file)
@@ -4,7 +4,7 @@
 #include <stdbool.h>
 
 /* FIXME: Check these! */
-#define INITIAL_TDB_MALLOC     "open.c", 395, FAILTEST_MALLOC
+#define INITIAL_TDB_MALLOC     "open.c", 396, FAILTEST_MALLOC
 #define URANDOM_OPEN           "open.c", 62, FAILTEST_OPEN
 #define URANDOM_READ           "open.c", 42, FAILTEST_READ
 
index 150150754a71dd9eb91c372be53926101af2fa8f..ffde0770255f4b5be717a11de721b1ad557e0e65 100644 (file)
@@ -10,7 +10,6 @@
 #include <limits.h>
 #include <string.h>
 #include <errno.h>
-#include <ccan/tdb2/tdb1.h>
 #include <ccan/tdb2/tdb1_private.h>
 #include <ccan/tap/tap.h>
 #include <stdio.h>