Commit b8e64e93 authored by Rusty Russell's avatar Rusty Russell

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.
parent a4f2eb98
......@@ -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;
......
......@@ -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);
......
#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 */
......@@ -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;
}
......@@ -26,7 +26,6 @@
*/
#include "private.h"
#include "tdb1.h"
#include <limits.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
......
......@@ -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
......
......@@ -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>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment