X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftdb2%2Ftdb2.h;h=5e354dfe9b5d562603d474dacef0e771de53cefe;hp=7032cd5006675be511be121aff8522a778e321f0;hb=52c4843176ce73484dd405261d13048bcd1b85e5;hpb=06e0037d97f5e1d83667ec40627cef862f3b7b85 diff --git a/ccan/tdb2/tdb2.h b/ccan/tdb2/tdb2.h index 7032cd50..5e354dfe 100644 --- a/ccan/tdb2/tdb2.h +++ b/ccan/tdb2/tdb2.h @@ -1,17 +1,17 @@ #ifndef CCAN_TDB2_H #define CCAN_TDB2_H -/* +/* Unix SMB/CIFS implementation. trivial database library Copyright (C) Andrew Tridgell 1999-2004 - + ** 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 @@ -40,6 +40,7 @@ extern "C" { /* For uint64_t */ #include #endif +#include /* flags to tdb_store() */ #define TDB_REPLACE 1 /* Unused */ @@ -56,46 +57,33 @@ extern "C" { #define TDB_NOSYNC 64 /* don't use synchronous transactions */ #define TDB_SEQNUM 128 /* maintain a sequence number */ #define TDB_VOLATILE 256 /* Activate the per-hashchain freelist, default 5 */ -#define TDB_ALLOW_NESTING 512 /* Allow transactions to nest */ -#define TDB_DISALLOW_NESTING 1024 /* Disallow transactions to nest */ /* error codes */ -enum TDB_ERROR {TDB_SUCCESS=0, TDB_ERR_CORRUPT, TDB_ERR_IO, TDB_ERR_LOCK, - TDB_ERR_OOM, TDB_ERR_EXISTS, TDB_ERR_NOLOCK, TDB_ERR_LOCK_TIMEOUT, - TDB_ERR_NOEXIST, TDB_ERR_EINVAL, TDB_ERR_RDONLY, - TDB_ERR_NESTING}; +enum TDB_ERROR {TDB_SUCCESS=0, TDB_ERR_CORRUPT, TDB_ERR_IO, TDB_ERR_LOCK, + TDB_ERR_OOM, TDB_ERR_EXISTS, TDB_ERR_NOEXIST, + TDB_ERR_EINVAL, TDB_ERR_RDONLY }; + +/* flags for tdb_summary. Logical or to combine. */ +enum tdb_summary_flags { TDB_SUMMARY_HISTOGRAMS = 1 }; -/* debugging uses one of the following levels */ -enum tdb_debug_level {TDB_DEBUG_FATAL = 0, TDB_DEBUG_ERROR, - TDB_DEBUG_WARNING, TDB_DEBUG_TRACE}; +/* logging uses one of the following levels */ +enum tdb_log_level {TDB_LOG_ERROR = 0, TDB_LOG_USE_ERROR, TDB_LOG_WARNING}; typedef struct tdb_data { unsigned char *dptr; size_t dsize; } TDB_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 - struct tdb_context; /* FIXME: Make typesafe */ -typedef void (*tdb_logfn_t)(struct tdb_context *, enum tdb_debug_level, void *priv, const char *, ...) PRINTF_ATTRIBUTE(4, 5); -typedef uint64_t (*tdb_hashfn_t)(const void *key, size_t len, uint64_t seed, - void *priv); +typedef int (*tdb_traverse_func)(struct tdb_context *, TDB_DATA, TDB_DATA, void *); enum tdb_attribute_type { TDB_ATTRIBUTE_LOG = 0, - TDB_ATTRIBUTE_HASH = 1 + TDB_ATTRIBUTE_HASH = 1, + TDB_ATTRIBUTE_SEED = 2, + TDB_ATTRIBUTE_STATS = 3 }; struct tdb_attribute_base { @@ -105,20 +93,58 @@ struct tdb_attribute_base { struct tdb_attribute_log { struct tdb_attribute_base base; /* .attr = TDB_ATTRIBUTE_LOG */ - tdb_logfn_t log_fn; + void (*log_fn)(struct tdb_context *tdb, + enum tdb_log_level level, + void *log_private, + const char *message); void *log_private; }; struct tdb_attribute_hash { struct tdb_attribute_base base; /* .attr = TDB_ATTRIBUTE_HASH */ - tdb_hashfn_t hash_fn; + uint64_t (*hash_fn)(const void *key, size_t len, uint64_t seed, + void *priv); void *hash_private; }; +struct tdb_attribute_seed { + struct tdb_attribute_base base; /* .attr = TDB_ATTRIBUTE_SEED */ + uint64_t seed; +}; + +struct tdb_attribute_stats { + struct tdb_attribute_base base; /* .attr = TDB_ATTRIBUTE_STATS */ + size_t size; /* = sizeof(struct tdb_attribute_stats) */ + uint64_t allocs; + uint64_t alloc_subhash; + uint64_t alloc_chain; + uint64_t alloc_bucket_exact; + uint64_t alloc_bucket_max; + uint64_t alloc_leftover; + uint64_t alloc_coalesce_tried; + uint64_t alloc_coalesce_lockfail; + uint64_t alloc_coalesce_race; + uint64_t alloc_coalesce_succeeded; + uint64_t alloc_coalesce_num_merged; + uint64_t compares; + uint64_t compare_wrong_bucket; + uint64_t compare_wrong_offsetbits; + uint64_t compare_wrong_keylen; + uint64_t compare_wrong_rechash; + uint64_t compare_wrong_keycmp; + uint64_t expands; + uint64_t frees; + uint64_t locks; + uint64_t lock_lowlevel; + uint64_t lock_nonblock; +}; + union tdb_attribute { struct tdb_attribute_base base; struct tdb_attribute_log log; struct tdb_attribute_hash hash; + struct tdb_attribute_seed seed; + struct tdb_attribute_stats stats; }; struct tdb_context *tdb_open(const char *name, int tdb_flags, @@ -128,12 +154,28 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags, struct tdb_data tdb_fetch(struct tdb_context *tdb, struct tdb_data key); int tdb_delete(struct tdb_context *tdb, struct tdb_data key); int tdb_store(struct tdb_context *tdb, struct tdb_data key, struct tdb_data dbuf, int flag); +int tdb_append(struct tdb_context *tdb, struct tdb_data key, struct tdb_data dbuf); +int tdb_chainlock(struct tdb_context *tdb, TDB_DATA key); +int tdb_chainunlock(struct tdb_context *tdb, TDB_DATA key); +int64_t tdb_traverse(struct tdb_context *tdb, tdb_traverse_func fn, void *p); +int64_t tdb_traverse_read(struct tdb_context *tdb, + tdb_traverse_func fn, void *p); +TDB_DATA tdb_firstkey(struct tdb_context *tdb); +TDB_DATA tdb_nextkey(struct tdb_context *tdb, TDB_DATA key); int tdb_close(struct tdb_context *tdb); int tdb_check(struct tdb_context *tdb, int (*check)(TDB_DATA key, TDB_DATA data, void *private_data), void *private_data); -enum TDB_ERROR tdb_error(struct tdb_context *tdb); +enum TDB_ERROR tdb_error(const struct tdb_context *tdb); +const char *tdb_errorstr(const struct tdb_context *tdb); + +int tdb_transaction_start(struct tdb_context *tdb); +void tdb_transaction_cancel(struct tdb_context *tdb); +int tdb_transaction_prepare_commit(struct tdb_context *tdb); +int tdb_transaction_commit(struct tdb_context *tdb); + +char *tdb_summary(struct tdb_context *tdb, enum tdb_summary_flags flags); extern struct tdb_data tdb_null;