Commit 19e6c1a2 authored by Rusty Russell's avatar Rusty Russell

tdb2: import TDB1 code.

We import the entire codebase, putting a "tdb1_" prefix on the files
and changing the "tdb_" prefix to "tdb1_" everywhere.

The next patches will gradually merge it with the TDB2 code where
necessary.
parent 47656743
#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/>.
*/
#ifndef _SAMBA_BUILD_
/* For mode_t */
#include <sys/types.h>
/* For O_* flags. */
#include <sys/stat.h>
/* For sig_atomic_t. */
#include <signal.h>
#endif
/** Flags to tdb1_store() */
#define TDB1_REPLACE 1 /** Unused */
#define TDB1_INSERT 2 /** Don't overwrite an existing entry */
#define TDB1_MODIFY 3 /** Don't create an existing entry */
/** Flags for tdb1_open() */
#define TDB1_DEFAULT 0 /** just a readability place holder */
#define TDB1_CLEAR_IF_FIRST 1 /** If this is the first open, wipe the db */
#define TDB1_INTERNAL 2 /** Don't store on disk */
#define TDB1_NOLOCK 4 /** Don't do any locking */
#define TDB1_NOMMAP 8 /** Don't use mmap */
#define TDB1_CONVERT 16 /** Convert endian (internal use) */
#define TDB1_BIGENDIAN 32 /** Header is big-endian (internal use) */
#define TDB1_NOSYNC 64 /** Don't use synchronous transactions */
#define TDB1_SEQNUM 128 /** Maintain a sequence number */
#define TDB1_VOLATILE 256 /** Activate the per-hashchain freelist, default 5 */
#define TDB1_ALLOW_NESTING 512 /** Allow transactions to nest */
#define TDB1_DISALLOW_NESTING 1024 /** Disallow transactions to nest */
#define TDB1_INCOMPATIBLE_HASH 2048 /** Better hashing: can't be opened by tdb < 1.2.6. */
/** The tdb error codes */
enum TDB1_ERROR {TDB1_SUCCESS=0, TDB1_ERR_CORRUPT, TDB1_ERR_IO, TDB1_ERR_LOCK,
TDB1_ERR_OOM, TDB1_ERR_EXISTS, TDB1_ERR_NOLOCK, TDB1_ERR_LOCK_TIMEOUT,
TDB1_ERR_NOEXIST, TDB1_ERR_EINVAL, TDB1_ERR_RDONLY,
TDB1_ERR_NESTING};
/** Debugging uses one of the following levels */
enum tdb1_debug_level {TDB1_DEBUG_FATAL = 0, TDB1_DEBUG_ERROR,
TDB1_DEBUG_WARNING, TDB1_DEBUG_TRACE};
/** The tdb data structure */
typedef struct TDB1_DATA {
unsigned char *dptr;
size_t dsize;
} TDB1_DATA;
#ifndef PRINTF_ATTRIBUTE
#if (__GNUC__ >= 3)
/** Use gcc attribute to check printf fns. a1 is the 1-based index of
* the parameter containing the format, and a2 the index of the first
* argument. Note that some gcc 2.x versions don't handle this
* properly **/
#define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2)))
#else
#define PRINTF_ATTRIBUTE(a1, a2)
#endif
#endif
/** This is the context structure that is returned from a db open. */
typedef struct tdb1_context TDB1_CONTEXT;
typedef int (*tdb1_traverse_func)(struct tdb1_context *, TDB1_DATA, TDB1_DATA, void *);
typedef void (*tdb1_log_func)(struct tdb1_context *, enum tdb1_debug_level, const char *, ...) PRINTF_ATTRIBUTE(3, 4);
typedef unsigned int (*tdb1_hash_func)(TDB1_DATA *key);
struct tdb1_logging_context {
tdb1_log_func log_fn;
void *log_private;
};
struct tdb1_context *tdb1_open(const char *name, int hash_size, int tdb1_flags,
int open_flags, mode_t mode);
struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flags,
int open_flags, mode_t mode,
const struct tdb1_logging_context *log_ctx,
tdb1_hash_func hash_fn);
void tdb1_set_max_dead(struct tdb1_context *tdb, int max_dead);
int tdb1_reopen(struct tdb1_context *tdb);
int tdb1_reopen_all(int parent_longlived);
void tdb1_set_logging_function(struct tdb1_context *tdb, const struct tdb1_logging_context *log_ctx);
enum TDB1_ERROR tdb1_error(struct tdb1_context *tdb);
const char *tdb1_errorstr(struct tdb1_context *tdb);
TDB1_DATA tdb1_fetch(struct tdb1_context *tdb, TDB1_DATA key);
int tdb1_parse_record(struct tdb1_context *tdb, TDB1_DATA key,
int (*parser)(TDB1_DATA key, TDB1_DATA data,
void *private_data),
void *private_data);
int tdb1_delete(struct tdb1_context *tdb, TDB1_DATA key);
int tdb1_store(struct tdb1_context *tdb, TDB1_DATA key, TDB1_DATA dbuf, int flag);
int tdb1_append(struct tdb1_context *tdb, TDB1_DATA key, TDB1_DATA new_dbuf);
int tdb1_close(struct tdb1_context *tdb);
TDB1_DATA tdb1_firstkey(struct tdb1_context *tdb);
TDB1_DATA tdb1_nextkey(struct tdb1_context *tdb, TDB1_DATA key);
int tdb1_traverse(struct tdb1_context *tdb, tdb1_traverse_func fn, void *private_data);
int tdb1_traverse_read(struct tdb1_context *tdb, tdb1_traverse_func fn, void *private_data);
int tdb1_exists(struct tdb1_context *tdb, TDB1_DATA key);
int tdb1_lockall(struct tdb1_context *tdb);
int tdb1_lockall_nonblock(struct tdb1_context *tdb);
int tdb1_unlockall(struct tdb1_context *tdb);
int tdb1_lockall_read(struct tdb1_context *tdb);
int tdb1_lockall_read_nonblock(struct tdb1_context *tdb);
int tdb1_unlockall_read(struct tdb1_context *tdb);
int tdb1_lockall_mark(struct tdb1_context *tdb);
int tdb1_lockall_unmark(struct tdb1_context *tdb);
const char *tdb1_name(struct tdb1_context *tdb);
int tdb1_fd(struct tdb1_context *tdb);
tdb1_log_func tdb1_log_fn(struct tdb1_context *tdb);
void *tdb1_get_logging_private(struct tdb1_context *tdb);
int tdb1_transaction_start(struct tdb1_context *tdb);
int tdb1_transaction_start_nonblock(struct tdb1_context *tdb);
int tdb1_transaction_prepare_commit(struct tdb1_context *tdb);
int tdb1_transaction_commit(struct tdb1_context *tdb);
int tdb1_transaction_cancel(struct tdb1_context *tdb);
int tdb1_get_seqnum(struct tdb1_context *tdb);
int tdb1_hash_size(struct tdb1_context *tdb);
size_t tdb1_map_size(struct tdb1_context *tdb);
int tdb1_get_flags(struct tdb1_context *tdb);
void tdb1_add_flags(struct tdb1_context *tdb, unsigned flag);
void tdb1_remove_flags(struct tdb1_context *tdb, unsigned flag);
void tdb1_enable_seqnum(struct tdb1_context *tdb);
void tdb1_increment_seqnum_nonblock(struct tdb1_context *tdb);
unsigned int tdb1_jenkins_hash(TDB1_DATA *key);
int tdb1_check(struct tdb1_context *tdb,
int (*check) (TDB1_DATA key, TDB1_DATA data, void *private_data),
void *private_data);
/* @} ******************************************************************/
/* Low level locking functions: use with care */
int tdb1_chainlock(struct tdb1_context *tdb, TDB1_DATA key);
int tdb1_chainlock_nonblock(struct tdb1_context *tdb, TDB1_DATA key);
int tdb1_chainunlock(struct tdb1_context *tdb, TDB1_DATA key);
int tdb1_chainlock_read(struct tdb1_context *tdb, TDB1_DATA key);
int tdb1_chainunlock_read(struct tdb1_context *tdb, TDB1_DATA key);
int tdb1_chainlock_mark(struct tdb1_context *tdb, TDB1_DATA key);
int tdb1_chainlock_unmark(struct tdb1_context *tdb, TDB1_DATA key);
void tdb1_setalarm_sigptr(struct tdb1_context *tdb, volatile sig_atomic_t *sigptr);
/* wipe and repack */
int tdb1_wipe_all(struct tdb1_context *tdb);
int tdb1_repack(struct tdb1_context *tdb);
/* Debug functions. Not used in production. */
void tdb1_dump_all(struct tdb1_context *tdb);
int tdb1_printfreelist(struct tdb1_context *tdb);
int tdb1_validate_freelist(struct tdb1_context *tdb, int *pnum_entries);
int tdb1_freelist_size(struct tdb1_context *tdb);
char *tdb1_summary(struct tdb1_context *tdb);
extern TDB1_DATA tdb1_null;
#endif /* tdb1.h */
This diff is collapsed.
/*
Unix SMB/CIFS implementation.
trivial database library
Copyright (C) Andrew Tridgell 1999-2005
Copyright (C) Paul `Rusty' Russell 2000
Copyright (C) Jeremy Allison 2000-2003
** 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 "tdb1_private.h"
static tdb1_off_t tdb1_dump_record(struct tdb1_context *tdb, int hash,
tdb1_off_t offset)
{
struct tdb1_record rec;
tdb1_off_t tailer_ofs, tailer;
if (tdb->methods->tdb1_read(tdb, offset, (char *)&rec,
sizeof(rec), TDB1_DOCONV()) == -1) {
printf("ERROR: failed to read record at %u\n", offset);
return 0;
}
printf(" rec: hash=%d offset=0x%08x next=0x%08x rec_len=%d "
"key_len=%d data_len=%d full_hash=0x%x magic=0x%x\n",
hash, offset, rec.next, rec.rec_len, rec.key_len, rec.data_len,
rec.full_hash, rec.magic);
tailer_ofs = offset + sizeof(rec) + rec.rec_len - sizeof(tdb1_off_t);
if (tdb1_ofs_read(tdb, tailer_ofs, &tailer) == -1) {
printf("ERROR: failed to read tailer at %u\n", tailer_ofs);
return rec.next;
}
if (tailer != rec.rec_len + sizeof(rec)) {
printf("ERROR: tailer does not match record! tailer=%u totalsize=%u\n",
(unsigned int)tailer, (unsigned int)(rec.rec_len + sizeof(rec)));
}
return rec.next;
}
static int tdb1_dump_chain(struct tdb1_context *tdb, int i)
{
tdb1_off_t rec_ptr, top;
top = TDB1_HASH_TOP(i);
if (tdb1_lock(tdb, i, F_WRLCK) != 0)
return -1;
if (tdb1_ofs_read(tdb, top, &rec_ptr) == -1)
return tdb1_unlock(tdb, i, F_WRLCK);
if (rec_ptr)
printf("hash=%d\n", i);
while (rec_ptr) {
rec_ptr = tdb1_dump_record(tdb, i, rec_ptr);
}
return tdb1_unlock(tdb, i, F_WRLCK);
}
_PUBLIC_ void tdb1_dump_all(struct tdb1_context *tdb)
{
int i;
for (i=0;i<tdb->header.hash_size;i++) {
tdb1_dump_chain(tdb, i);
}
printf("freelist:\n");
tdb1_dump_chain(tdb, -1);
}
_PUBLIC_ int tdb1_printfreelist(struct tdb1_context *tdb)
{
int ret;
long total_free = 0;
tdb1_off_t offset, rec_ptr;
struct tdb1_record rec;
if ((ret = tdb1_lock(tdb, -1, F_WRLCK)) != 0)
return ret;
offset = TDB1_FREELIST_TOP;
/* read in the freelist top */
if (tdb1_ofs_read(tdb, offset, &rec_ptr) == -1) {
tdb1_unlock(tdb, -1, F_WRLCK);
return 0;
}
printf("freelist top=[0x%08x]\n", rec_ptr );
while (rec_ptr) {
if (tdb->methods->tdb1_read(tdb, rec_ptr, (char *)&rec,
sizeof(rec), TDB1_DOCONV()) == -1) {
tdb1_unlock(tdb, -1, F_WRLCK);
return -1;
}
if (rec.magic != TDB1_FREE_MAGIC) {
printf("bad magic 0x%08x in free list\n", rec.magic);
tdb1_unlock(tdb, -1, F_WRLCK);
return -1;
}
printf("entry offset=[0x%08x], rec.rec_len = [0x%08x (%d)] (end = 0x%08x)\n",
rec_ptr, rec.rec_len, rec.rec_len, rec_ptr + rec.rec_len);
total_free += rec.rec_len;
/* move to the next record */
rec_ptr = rec.next;
}
printf("total rec_len = [0x%08x (%d)]\n", (int)total_free,
(int)total_free);
return tdb1_unlock(tdb, -1, F_WRLCK);
}
/*
Unix SMB/CIFS implementation.
trivial database library
Copyright (C) Andrew Tridgell 1999-2005
Copyright (C) Paul `Rusty' Russell 2000
Copyright (C) Jeremy Allison 2000-2003
** 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 "tdb1_private.h"
_PUBLIC_ enum TDB1_ERROR tdb1_error(struct tdb1_context *tdb)
{
return tdb->ecode;
}
static struct tdb1_errname {
enum TDB1_ERROR ecode; const char *estring;
} emap[] = { {TDB1_SUCCESS, "Success"},
{TDB1_ERR_CORRUPT, "Corrupt database"},
{TDB1_ERR_IO, "IO Error"},
{TDB1_ERR_LOCK, "Locking error"},
{TDB1_ERR_OOM, "Out of memory"},
{TDB1_ERR_EXISTS, "Record exists"},
{TDB1_ERR_NOLOCK, "Lock exists on other keys"},
{TDB1_ERR_EINVAL, "Invalid parameter"},
{TDB1_ERR_NOEXIST, "Record does not exist"},
{TDB1_ERR_RDONLY, "write not permitted"} };
/* Error string for the last tdb error */
_PUBLIC_ const char *tdb1_errorstr(struct tdb1_context *tdb)
{
uint32_t i;
for (i = 0; i < sizeof(emap) / sizeof(struct tdb1_errname); i++)
if (tdb->ecode == emap[i].ecode)
return emap[i].estring;
return "Invalid error code";
}
This diff is collapsed.
/*
Unix SMB/CIFS implementation.
trivial database library
Copyright (C) Jeremy Allison 2006
** 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 "tdb1_private.h"
/* Check the freelist is good and contains no loops.
Very memory intensive - only do this as a consistency
checker. Heh heh - uses an in memory tdb as the storage
for the "seen" record list. For some reason this strikes
me as extremely clever as I don't have to write another tree
data structure implementation :-).
*/
static int seen_insert(struct tdb1_context *mem_tdb, tdb1_off_t rec_ptr)
{
TDB1_DATA key, data;
memset(&data, '\0', sizeof(data));
key.dptr = (unsigned char *)&rec_ptr;
key.dsize = sizeof(rec_ptr);
return tdb1_store(mem_tdb, key, data, TDB1_INSERT);
}
_PUBLIC_ int tdb1_validate_freelist(struct tdb1_context *tdb, int *pnum_entries)
{
struct tdb1_context *mem_tdb = NULL;
struct tdb1_record rec;
tdb1_off_t rec_ptr, last_ptr;
int ret = -1;
*pnum_entries = 0;
mem_tdb = tdb1_open("flval", tdb->header.hash_size,
TDB1_INTERNAL, O_RDWR, 0600);
if (!mem_tdb) {
return -1;
}
if (tdb1_lock(tdb, -1, F_WRLCK) == -1) {
tdb1_close(mem_tdb);
return 0;
}
last_ptr = TDB1_FREELIST_TOP;
/* Store the TDB1_FREELIST_TOP record. */
if (seen_insert(mem_tdb, last_ptr) == -1) {
tdb->ecode = TDB1_ERR_CORRUPT;
ret = -1;
goto fail;
}
/* read in the freelist top */
if (tdb1_ofs_read(tdb, TDB1_FREELIST_TOP, &rec_ptr) == -1) {
goto fail;
}
while (rec_ptr) {
/* If we can't store this record (we've seen it
before) then the free list has a loop and must
be corrupt. */
if (seen_insert(mem_tdb, rec_ptr)) {
tdb->ecode = TDB1_ERR_CORRUPT;
ret = -1;
goto fail;
}
if (tdb1_rec_free_read(tdb, rec_ptr, &rec) == -1) {
goto fail;
}
/* move to the next record */
last_ptr = rec_ptr;
rec_ptr = rec.next;
*pnum_entries += 1;
}
ret = 0;
fail:
tdb1_close(mem_tdb);
tdb1_unlock(tdb, -1, F_WRLCK);
return ret;
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/*
Trivial Database: human-readable summary code
Copyright (C) Rusty Russell 2010
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 "tdb1_private.h"
#define SUMMARY_FORMAT1 \
"Size of file/data: %u/%zu\n" \
"Number of records: %zu\n" \
"Smallest/average/largest keys: %zu/%zu/%zu\n" \
"Smallest/average/largest data: %zu/%zu/%zu\n" \
"Smallest/average/largest padding: %zu/%zu/%zu\n" \
"Number of dead records: %zu\n" \
"Smallest/average/largest dead records: %zu/%zu/%zu\n" \
"Number of free records: %zu\n" \
"Smallest/average/largest free records: %zu/%zu/%zu\n" \
"Number of hash chains: %zu\n" \
"Smallest/average/largest hash chains: %zu/%zu/%zu\n" \
"Number of uncoalesced records: %zu\n" \
"Smallest/average/largest uncoalesced runs: %zu/%zu/%zu\n" \
"Percentage keys/data/padding/free/dead/rechdrs&tailers/hashes: %.0f/%.0f/%.0f/%.0f/%.0f/%.0f/%.0f\n"
/* We don't use tally module, to keep upstream happy. */
struct tally {
size_t min, max, total;
size_t num;
};
static void tally1_init(struct tally *tally)
{
tally->total = 0;
tally->num = 0;
tally->min = tally->max = 0;
}
static void tally1_add(struct tally *tally, size_t len)
{
if (tally->num == 0)
tally->max = tally->min = len;
else if (len > tally->max)
tally->max = len;
else if (len < tally->min)
tally->min = len;
tally->num++;
tally->total += len;
}
static size_t tally1_mean(const struct tally *tally)
{
if (!tally->num)
return 0;
return tally->total / tally->num;
}
static size_t get_hash_length(struct tdb1_context *tdb, unsigned int i)
{
tdb1_off_t rec_ptr;
size_t count = 0;
if (tdb1_ofs_read(tdb, TDB1_HASH_TOP(i), &rec_ptr) == -1)
return 0;
/* keep looking until we find the right record */
while (rec_ptr) {
struct tdb1_record r;
++count;
if (tdb1_rec_read(tdb, rec_ptr, &r) == -1)
return 0;
rec_ptr = r.next;
}
return count;
}
_PUBLIC_ char *tdb1_summary(struct tdb1_context *tdb)
{
tdb1_off_t off, rec_off;
struct tally freet, keys, data, dead, extra, hash, uncoal;
struct tdb1_record rec;
char *ret = NULL;
bool locked;
size_t len, unc = 0;
struct tdb1_record recovery;
/* Read-only databases use no locking at all: it's best-effort.
* We may have a write lock already, so skip that case too. */
if (tdb->read_only || tdb->allrecord_lock.count != 0) {
locked = false;
} else {
if (tdb1_lockall_read(tdb) == -1)
return NULL;
locked = true;
}
if (tdb1_recovery_area(tdb, tdb->methods, &rec_off, &recovery) != 0) {
goto unlock;
}
tally1_init(&freet);
tally1_init(&keys);
tally1_init(&data);
tally1_init(&dead);
tally1_init(&extra);
tally1_init(&hash);
tally1_init(&uncoal);
for (off = TDB1_DATA_START(tdb->header.hash_size);
off < tdb->map_size - 1;
off += sizeof(rec) + rec.rec_len) {
if (tdb->methods->tdb1_read(tdb, off, &rec, sizeof(rec),
TDB1_DOCONV()) == -1)
goto unlock;
switch (rec.magic) {
case TDB1_MAGIC:
tally1_add(&keys, rec.key_len);
tally1_add(&data, rec.data_len);
tally1_add(&extra, rec.rec_len - (rec.key_len
+ rec.data_len));
if (unc > 1)
tally1_add(&uncoal, unc - 1);
unc = 0;
break;
case TDB1_FREE_MAGIC:
tally1_add(&freet, rec.rec_len);
unc++;
break;
/* If we crash after ftruncate, we can get zeroes or fill. */
case TDB1_RECOVERY_INVALID_MAGIC:
case 0x42424242:
unc++;
/* If it's a valid recovery, we can trust rec_len. */
if (off != rec_off) {
rec.rec_len = tdb1_dead_space(tdb, off)
- sizeof(rec);
}
/* Fall through */
case TDB1_DEAD_MAGIC:
tally1_add(&dead, rec.rec_len);
break;
default:
TDB1_LOG((tdb, TDB1_DEBUG_ERROR,
"Unexpected record magic 0x%x at offset %d\n",
rec.magic, off));
goto unlock;
}
}
if (unc > 1)
tally1_add(&uncoal, unc - 1);
for (off = 0; off < tdb->header.hash_size; off++)
tally1_add(&hash, get_hash_length(tdb, off));
/* 20 is max length of a %zu. */
len = strlen(SUMMARY_FORMAT1) + 35*20 + 1;
ret = (char *)malloc(len);
if (!ret)
goto unlock;
snprintf(ret, len, SUMMARY_FORMAT1,
tdb->map_size, keys.total+data.total,
keys.num,
keys.min, tally1_mean(&keys), keys.max,
data.min, tally1_mean(&data), data.max,
extra.min, tally1_mean(&extra), extra.max,
dead.num,
dead.min, tally1_mean(&dead), dead.max,
freet.num,
freet.min, tally1_mean(&freet), freet.max,
hash.num,
hash.min, tally1_mean(&hash), hash.max,
uncoal.total,
uncoal.min, tally1_mean(&uncoal), uncoal.max,
keys.total * 100.0 / tdb->map_size,
data.total * 100.0 / tdb->map_size,
extra.total * 100.0 / tdb->map_size,
freet.total * 100.0 / tdb->map_size,
dead.total * 100.0 / tdb->map_size,
(keys.num + freet.num + dead.num)
* (sizeof(struct tdb1_record) + sizeof(uint32_t))
* 100.0 / tdb->map_size,
tdb->header.hash_size * sizeof(tdb1_off_t)
* 100.0 / tdb->map_size);
unlock:
if (locked) {
tdb1_unlockall_read(tdb);
}
return ret;
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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