X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Ftdb2%2Ftdb1_private.h;h=bff967b25b883ea38fe5992489f8dffd9294ae59;hb=4dc29a338fadeac805b369b4b0851c02f1b152c7;hp=809f13555552ac85811946f1d8dd212cc92f0200;hpb=444fade529f68eb2b0aebbc8de442478c5c6f916;p=ccan
diff --git a/ccan/tdb2/tdb1_private.h b/ccan/tdb2/tdb1_private.h
index 809f1355..bff967b2 100644
--- a/ccan/tdb2/tdb1_private.h
+++ b/ccan/tdb2/tdb1_private.h
@@ -25,39 +25,48 @@
License along with this library; if not, see .
*/
-#ifndef _SAMBA_BUILD_
-#include "config.h"
-/* This keeps us consistent with TDB2 code. */
-#if HAVE_FILE_OFFSET_BITS
-#define _FILE_OFFSET_BITS 64
-#endif
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#else
-#include "replace.h"
-#include "system/filesys.h"
-#include "system/time.h"
-#include "system/shmem.h"
-#include "system/select.h"
-#include "system/wait.h"
-#endif
-
+#include "private.h"
#include "tdb1.h"
-/* Temporary wrapper to avoid undue churn in test/ */
-#define tdb1_error(tdb) ((tdb)->ecode)
+/**** FIXME: Type overrides for tdb2, for transition! */
+#define tdb_logerr(tdb, ecode, level, ...) \
+ tdb_logerr((struct tdb_context *)(tdb), (ecode), (level), __VA_ARGS__)
+
+#define tdb_error(tdb) \
+ tdb_error((struct tdb_context *)(tdb))
+
+#define tdb_brlock(tdb1, rw_type, offset, len, flags) \
+ tdb_brlock((struct tdb_context *)(tdb1), \
+ (rw_type), (offset), (len), (flags))
+
+#define tdb_brunlock(tdb1, rw_type, offset, len) \
+ tdb_brunlock((struct tdb_context *)(tdb1), (rw_type), (offset), (len))
+
+#define tdb_nest_lock(tdb1, offset, ltype, flags) \
+ tdb_nest_lock((struct tdb_context *)(tdb1), (offset), (ltype), (flags))
+
+#define tdb_nest_unlock(tdb1, offset, ltype) \
+ tdb_nest_unlock((struct tdb_context *)(tdb1), (offset), (ltype))
+
+#define tdb_allrecord_lock(tdb1, offset, flags, upgradable) \
+ tdb_allrecord_lock((struct tdb_context *)(tdb1), \
+ (offset), (flags), (upgradable))
+
+#define tdb_allrecord_unlock(tdb1, ltype) \
+ tdb_allrecord_unlock((struct tdb_context *)(tdb1), (ltype))
+
+#define tdb_allrecord_upgrade(tdb1, start) \
+ tdb_allrecord_upgrade((struct tdb_context *)(tdb1), (start))
+
+#define tdb_hash(tdb1, ptr, len) \
+ tdb_hash((struct tdb_context *)(tdb1), (ptr), (len))
+
+#define tdb_lock_gradual(tdb1, ltype, flags, off, len) \
+ tdb_lock_gradual((struct tdb_context *)(tdb1), \
+ (ltype), (flags), (off), (len))
+/***** END FIXME ***/
+
+#include
/* #define TDB_TRACE 1 */
#ifndef HAVE_GETPAGESIZE
@@ -83,7 +92,6 @@ typedef uint32_t tdb1_off_t;
#define offsetof(t,f) ((unsigned int)&((t *)0)->f)
#endif
-#define TDB1_MAGIC_FOOD "TDB file\n"
#define TDB1_VERSION (0x26011967 + 6)
#define TDB1_MAGIC (0x26011999U)
#define TDB1_FREE_MAGIC (~TDB1_MAGIC)
@@ -106,11 +114,6 @@ typedef uint32_t tdb1_off_t;
#define TDB1_PAD_BYTE 0x42
#define TDB1_PAD_U32 0x42424242
-/* NB assumes there is a local variable called "tdb" that is the
- * current context, also takes doubly-parenthesized print-style
- * argument. */
-#define TDB1_LOG(x) tdb->log.log_fn x
-
/* lock offsets */
#define TDB1_OPEN_LOCK 0
#define TDB1_ACTIVE_LOCK 4
@@ -123,7 +126,7 @@ typedef uint32_t tdb1_off_t;
#define TDB1_BUCKET(hash) ((hash) % tdb->header.hash_size)
-#define TDB1_DOCONV() (tdb->flags & TDB1_CONVERT)
+#define TDB1_DOCONV() (tdb->flags & TDB_CONVERT)
#define TDB1_CONV(x) (TDB1_DOCONV() ? tdb1_convert(&x, sizeof(x)) : &x)
/* the body of the database is made of one tdb1_record for the free space
@@ -156,17 +159,11 @@ struct tdb1_header {
tdb1_off_t rwlocks; /* obsolete - kept to detect old formats */
tdb1_off_t recovery_start; /* offset of transaction recovery region */
tdb1_off_t sequence_number; /* used when TDB1_SEQNUM is set */
- uint32_t magic1_hash; /* hash of TDB1_MAGIC_FOOD. */
+ uint32_t magic1_hash; /* hash of TDB_MAGIC_FOOD. */
uint32_t magic2_hash; /* hash of TDB1_MAGIC. */
tdb1_off_t reserved[27];
};
-struct tdb1_lock_type {
- uint32_t off;
- uint32_t count;
- uint32_t ltype;
-};
-
struct tdb1_traverse_lock {
struct tdb1_traverse_lock *next;
uint32_t off;
@@ -174,14 +171,6 @@ struct tdb1_traverse_lock {
int lock_rw;
};
-enum tdb1_lock_flags {
- /* WAIT == F_SETLKW, NOWAIT == F_SETLK */
- TDB1_LOCK_NOWAIT = 0,
- TDB1_LOCK_WAIT = 1,
- /* If set, don't log an error on failure. */
- TDB1_LOCK_PROBE = 2,
-};
-
struct tdb1_context;
struct tdb1_methods {
@@ -193,26 +182,45 @@ struct tdb1_methods {
};
struct tdb1_context {
+ struct tdb1_context *next;
+
char *name; /* the name of the database */
- void *map_ptr; /* where it is currently mapped */
- int fd; /* open file descriptor for the database */
- tdb1_len_t map_size; /* how much space has been mapped */
- int read_only; /* opened read-only */
+
+ /* Logging function */
+ void (*log_fn)(struct tdb1_context *tdb,
+ enum tdb_log_level level,
+ enum TDB_ERROR ecode,
+ const char *message,
+ void *data);
+ void *log_data;
+
+ /* Last error we returned. */
+ enum TDB_ERROR last_error; /* error code for last tdb error */
+
+ /* The actual file information */
+ struct tdb_file *file;
+
+ int open_flags; /* flags used in the open - needed by reopen */
+
+ /* low level (fnctl) lock functions. */
+ int (*lock_fn)(int fd, int rw, off_t off, off_t len, bool w, void *);
+ int (*unlock_fn)(int fd, int rw, off_t off, off_t len, void *);
+ void *lock_data;
+
+ uint32_t flags; /* the flags passed to tdb1_open */
+
+ /* Our statistics. */
+ struct tdb_attribute_stats stats;
+
+ /* Hash function. */
+ uint64_t (*hash_fn)(const void *key, size_t len, uint64_t seed, void *);
+ void *hash_data;
+ uint64_t hash_seed;
+
int traverse_read; /* read-only traversal */
int traverse_write; /* read-write traversal */
- struct tdb1_lock_type allrecord_lock; /* .offset == upgradable */
- int num_lockrecs;
- struct tdb1_lock_type *lockrecs; /* only real locks, all with count>0 */
- enum TDB1_ERROR ecode; /* error code for last tdb error */
struct tdb1_header header; /* a cached copy of the header */
- uint32_t flags; /* the flags passed to tdb1_open */
struct tdb1_traverse_lock travlocks; /* current traversal locks */
- struct tdb1_context *next; /* all tdbs to avoid multiple opens */
- dev_t device; /* uniquely identifies this tdb */
- ino_t inode; /* uniquely identifies this tdb */
- struct tdb1_logging_context log;
- unsigned int (*hash_fn)(TDB1_DATA *key);
- int open_flags; /* flags used in the open - needed by reopen */
const struct tdb1_methods *methods;
struct tdb1_transaction *transaction;
int page_size;
@@ -226,25 +234,25 @@ int tdb1_munmap(struct tdb1_context *tdb);
void tdb1_mmap(struct tdb1_context *tdb);
int tdb1_lock(struct tdb1_context *tdb, int list, int ltype);
int tdb1_nest_lock(struct tdb1_context *tdb, uint32_t offset, int ltype,
- enum tdb1_lock_flags flags);
+ enum tdb_lock_flags flags);
int tdb1_nest_unlock(struct tdb1_context *tdb, uint32_t offset, int ltype);
int tdb1_unlock(struct tdb1_context *tdb, int list, int ltype);
int tdb1_brlock(struct tdb1_context *tdb,
int rw_type, tdb1_off_t offset, size_t len,
- enum tdb1_lock_flags flags);
+ enum tdb_lock_flags flags);
int tdb1_brunlock(struct tdb1_context *tdb,
int rw_type, tdb1_off_t offset, size_t len);
bool tdb1_have_extra_locks(struct tdb1_context *tdb);
void tdb1_release_transaction_locks(struct tdb1_context *tdb);
int tdb1_transaction_lock(struct tdb1_context *tdb, int ltype,
- enum tdb1_lock_flags lockflags);
+ enum tdb_lock_flags lockflags);
int tdb1_transaction_unlock(struct tdb1_context *tdb, int ltype);
int tdb1_recovery_area(struct tdb1_context *tdb,
const struct tdb1_methods *methods,
tdb1_off_t *recovery_offset,
struct tdb1_record *rec);
int tdb1_allrecord_lock(struct tdb1_context *tdb, int ltype,
- enum tdb1_lock_flags flags, bool upgradable);
+ enum tdb_lock_flags flags, bool upgradable);
int tdb1_allrecord_unlock(struct tdb1_context *tdb, int ltype);
int tdb1_allrecord_upgrade(struct tdb1_context *tdb);
int tdb1_write_lock_record(struct tdb1_context *tdb, tdb1_off_t off);
@@ -263,12 +271,12 @@ int tdb1_rec_read(struct tdb1_context *tdb, tdb1_off_t offset, struct tdb1_recor
int tdb1_rec_write(struct tdb1_context *tdb, tdb1_off_t offset, struct tdb1_record *rec);
int tdb1_do_delete(struct tdb1_context *tdb, tdb1_off_t rec_ptr, struct tdb1_record *rec);
unsigned char *tdb1_alloc_read(struct tdb1_context *tdb, tdb1_off_t offset, tdb1_len_t len);
-int tdb1_parse_data(struct tdb1_context *tdb, TDB1_DATA key,
+int tdb1_parse_data(struct tdb1_context *tdb, TDB_DATA key,
tdb1_off_t offset, tdb1_len_t len,
- int (*parser)(TDB1_DATA key, TDB1_DATA data,
+ int (*parser)(TDB_DATA key, TDB_DATA data,
void *private_data),
void *private_data);
-tdb1_off_t tdb1_find_lock_hash(struct tdb1_context *tdb, TDB1_DATA key, uint32_t hash, int locktype,
+tdb1_off_t tdb1_find_lock_hash(struct tdb1_context *tdb, TDB_DATA key, uint32_t hash, int locktype,
struct tdb1_record *rec);
void tdb1_io_init(struct tdb1_context *tdb);
int tdb1_expand(struct tdb1_context *tdb, tdb1_off_t size);
@@ -278,6 +286,6 @@ bool tdb1_write_all(int fd, const void *buf, size_t count);
int tdb1_transaction_recover(struct tdb1_context *tdb);
void tdb1_header_hash(struct tdb1_context *tdb,
uint32_t *magic1_hash, uint32_t *magic2_hash);
-unsigned int tdb1_old_hash(TDB1_DATA *key);
+uint64_t tdb1_old_hash(const void *key, size_t len, uint64_t seed, void *);
size_t tdb1_dead_space(struct tdb1_context *tdb, tdb1_off_t off);
#endif /* CCAN_TDB2_TDB1_PRIVATE_H */