From: Rusty Russell Date: Wed, 31 Aug 2011 06:01:07 +0000 (+0930) Subject: tdb2: add tdb_attribute_tdb1_max_dead X-Git-Url: http://git.ozlabs.org/?p=ccan;a=commitdiff_plain;h=b8e64e9346793164651a36eccb3c205077e5c91b tdb2: add tdb_attribute_tdb1_max_dead 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. --- diff --git a/ccan/tdb2/open.c b/ccan/tdb2/open.c index 3217a9b2..3e3b083e 100644 --- a/ccan/tdb2/open.c +++ b/ccan/tdb2/open.c @@ -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; diff --git a/ccan/tdb2/private.h b/ccan/tdb2/private.h index b801ffaf..30338d77 100644 --- a/ccan/tdb2/private.h +++ b/ccan/tdb2/private.h @@ -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 index c46abc7e..00000000 --- a/ccan/tdb2/tdb1.h +++ /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 . -*/ -#include "tdb2.h" - -#ifndef _SAMBA_BUILD_ -/* For mode_t */ -#include -/* For O_* flags. */ -#include -#endif - - -void tdb1_set_max_dead(struct tdb_context *tdb, int max_dead); - -/* @} ******************************************************************/ - -#endif /* tdb1.h */ diff --git a/ccan/tdb2/tdb1_open.c b/ccan/tdb2/tdb1_open.c index df46450c..e22a6d14 100644 --- a/ccan/tdb2/tdb1_open.c +++ b/ccan/tdb2/tdb1_open.c @@ -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; -} diff --git a/ccan/tdb2/tdb1_private.h b/ccan/tdb2/tdb1_private.h index 5d27c785..ea147a89 100644 --- a/ccan/tdb2/tdb1_private.h +++ b/ccan/tdb2/tdb1_private.h @@ -26,7 +26,6 @@ */ #include "private.h" -#include "tdb1.h" #include diff --git a/ccan/tdb2/tdb2.h b/ccan/tdb2/tdb2.h index be5d5002..525fbd71 100644 --- a/ccan/tdb2/tdb2.h +++ b/ccan/tdb2/tdb2.h @@ -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 diff --git a/ccan/tdb2/test/failtest_helper.h b/ccan/tdb2/test/failtest_helper.h index 54529fe8..02acac8c 100644 --- a/ccan/tdb2/test/failtest_helper.h +++ b/ccan/tdb2/test/failtest_helper.h @@ -4,7 +4,7 @@ #include /* 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 diff --git a/ccan/tdb2/test/tdb1-external-agent.c b/ccan/tdb2/test/tdb1-external-agent.c index 15015075..ffde0770 100644 --- a/ccan/tdb2/test/tdb1-external-agent.c +++ b/ccan/tdb2/test/tdb1-external-agent.c @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include