summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2011-09-14 08:06:13 +0930
committerRusty Russell <rusty@rustcorp.com.au>2011-09-14 08:06:13 +0930
commitb50b48f575d8ad2a709c89dab0a64e19e45d7b08 (patch)
treef5cddc9072fa37e6c9692fa30fe0c7d45547af65 /lib
parent13238912facb04ab3aafeb020de6226659d83e6b (diff)
downloadsamba-b50b48f575d8ad2a709c89dab0a64e19e45d7b08.tar.gz
samba-b50b48f575d8ad2a709c89dab0a64e19e45d7b08.tar.bz2
samba-b50b48f575d8ad2a709c89dab0a64e19e45d7b08.zip
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. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (Imported from CCAN commit b8e64e9346793164651a36eccb3c205077e5c91b)
Diffstat (limited to 'lib')
-rw-r--r--lib/tdb2/open.c12
-rw-r--r--lib/tdb2/private.h6
-rw-r--r--lib/tdb2/tdb1.h43
-rw-r--r--lib/tdb2/tdb1_open.c29
-rw-r--r--lib/tdb2/tdb1_private.h1
-rw-r--r--lib/tdb2/tdb2.h15
-rw-r--r--lib/tdb2/test/failtest_helper.h2
-rw-r--r--lib/tdb2/test/tdb1-external-agent.c1
8 files changed, 41 insertions, 68 deletions
diff --git a/lib/tdb2/open.c b/lib/tdb2/open.c
index 0a4ca5d17e..46e22a324c 100644
--- a/lib/tdb2/open.c
+++ b/lib/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/lib/tdb2/private.h b/lib/tdb2/private.h
index f4fba85d3e..6e28692c34 100644
--- a/lib/tdb2/private.h
+++ b/lib/tdb2/private.h
@@ -651,8 +651,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/lib/tdb2/tdb1.h b/lib/tdb2/tdb1.h
deleted file mode 100644
index c46abc7e5e..0000000000
--- a/lib/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 <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 */
diff --git a/lib/tdb2/tdb1_open.c b/lib/tdb2/tdb1_open.c
index df46450c90..e22a6d1428 100644
--- a/lib/tdb2/tdb1_open.c
+++ b/lib/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/lib/tdb2/tdb1_private.h b/lib/tdb2/tdb1_private.h
index 5d27c785fc..ea147a8967 100644
--- a/lib/tdb2/tdb1_private.h
+++ b/lib/tdb2/tdb1_private.h
@@ -26,7 +26,6 @@
*/
#include "private.h"
-#include "tdb1.h"
#include <limits.h>
diff --git a/lib/tdb2/tdb2.h b/lib/tdb2/tdb2.h
index 0eda9ef84b..6a7cab617d 100644
--- a/lib/tdb2/tdb2.h
+++ b/lib/tdb2/tdb2.h
@@ -633,6 +633,7 @@ enum tdb_attribute_type {
TDB_ATTRIBUTE_OPENHOOK = 4,
TDB_ATTRIBUTE_FLOCK = 5,
TDB_ATTRIBUTE_TDB1_HASHSIZE = 128,
+ TDB_ATTRIBUTE_TDB1_MAX_DEAD = 129,
};
/**
@@ -878,6 +879,19 @@ struct tdb_attribute_tdb1_hashsize {
};
/**
+ * 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.
*
* This represents all the known attributes.
@@ -896,6 +910,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/lib/tdb2/test/failtest_helper.h b/lib/tdb2/test/failtest_helper.h
index 54529fe893..02acac8c3c 100644
--- a/lib/tdb2/test/failtest_helper.h
+++ b/lib/tdb2/test/failtest_helper.h
@@ -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
diff --git a/lib/tdb2/test/tdb1-external-agent.c b/lib/tdb2/test/tdb1-external-agent.c
index 150150754a..ffde077025 100644
--- a/lib/tdb2/test/tdb1-external-agent.c
+++ b/lib/tdb2/test/tdb1-external-agent.c
@@ -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>