Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
ccan
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mirror
ccan
Commits
8a47d50d
Commit
8a47d50d
authored
Aug 31, 2011
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tdb2: Make tdb1 share tdb_store flags, struct tdb_data and TDB_MAGIC_FOOD.
parent
91993735
Changes
27
Hide whitespace changes
Inline
Side-by-side
Showing
27 changed files
with
168 additions
and
187 deletions
+168
-187
ccan/tdb2/tdb1.h
ccan/tdb2/tdb1.h
+18
-28
ccan/tdb2/tdb1_check.c
ccan/tdb2/tdb1_check.c
+7
-7
ccan/tdb2/tdb1_hash.c
ccan/tdb2/tdb1_hash.c
+2
-2
ccan/tdb2/tdb1_io.c
ccan/tdb2/tdb1_io.c
+3
-3
ccan/tdb2/tdb1_lock.c
ccan/tdb2/tdb1_lock.c
+22
-22
ccan/tdb2/tdb1_open.c
ccan/tdb2/tdb1_open.c
+8
-8
ccan/tdb2/tdb1_private.h
ccan/tdb2/tdb1_private.h
+10
-19
ccan/tdb2/tdb1_tdb.c
ccan/tdb2/tdb1_tdb.c
+29
-29
ccan/tdb2/tdb1_transaction.c
ccan/tdb2/tdb1_transaction.c
+3
-3
ccan/tdb2/tdb1_traverse.c
ccan/tdb2/tdb1_traverse.c
+7
-7
ccan/tdb2/test/run-tdb1-3G-file.c
ccan/tdb2/test/run-tdb1-3G-file.c
+5
-5
ccan/tdb2/test/run-tdb1-check.c
ccan/tdb2/test/run-tdb1-check.c
+2
-2
ccan/tdb2/test/run-tdb1-corrupt.c
ccan/tdb2/test/run-tdb1-corrupt.c
+4
-4
ccan/tdb2/test/run-tdb1-die-during-transaction.c
ccan/tdb2/test/run-tdb1-die-during-transaction.c
+3
-3
ccan/tdb2/test/run-tdb1-endian.c
ccan/tdb2/test/run-tdb1-endian.c
+5
-5
ccan/tdb2/test/run-tdb1-incompatible.c
ccan/tdb2/test/run-tdb1-incompatible.c
+5
-5
ccan/tdb2/test/run-tdb1-nested-transactions.c
ccan/tdb2/test/run-tdb1-nested-transactions.c
+2
-2
ccan/tdb2/test/run-tdb1-nested-traverse.c
ccan/tdb2/test/run-tdb1-nested-traverse.c
+6
-6
ccan/tdb2/test/run-tdb1-no-lock-during-traverse.c
ccan/tdb2/test/run-tdb1-no-lock-during-traverse.c
+4
-4
ccan/tdb2/test/run-tdb1-open-during-transaction.c
ccan/tdb2/test/run-tdb1-open-during-transaction.c
+2
-2
ccan/tdb2/test/run-tdb1-readonly-check.c
ccan/tdb2/test/run-tdb1-readonly-check.c
+3
-3
ccan/tdb2/test/run-tdb1-summary.c
ccan/tdb2/test/run-tdb1-summary.c
+3
-3
ccan/tdb2/test/run-tdb1-traverse-in-transaction.c
ccan/tdb2/test/run-tdb1-traverse-in-transaction.c
+5
-5
ccan/tdb2/test/run-tdb1-wronghash-fail.c
ccan/tdb2/test/run-tdb1-wronghash-fail.c
+2
-2
ccan/tdb2/test/run-tdb1-zero-append.c
ccan/tdb2/test/run-tdb1-zero-append.c
+1
-1
ccan/tdb2/test/run-tdb1.c
ccan/tdb2/test/run-tdb1.c
+5
-5
ccan/tdb2/test/tdb1-external-agent.c
ccan/tdb2/test/tdb1-external-agent.c
+2
-2
No files found.
ccan/tdb2/tdb1.h
View file @
8a47d50d
...
...
@@ -35,10 +35,6 @@
#include <sys/stat.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 */
...
...
@@ -55,19 +51,13 @@
#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 data structure */
typedef
struct
TDB1_DATA
{
unsigned
char
*
dptr
;
size_t
dsize
;
}
TDB1_DATA
;
/** 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
*
,
TDB
1_DATA
,
TDB1
_DATA
,
void
*
);
typedef
int
(
*
tdb1_traverse_func
)(
struct
tdb1_context
*
,
TDB
_DATA
,
TDB
_DATA
,
void
*
);
typedef
void
(
*
tdb1_log_func
)(
struct
tdb1_context
*
,
enum
tdb_log_level
,
enum
TDB_ERROR
,
const
char
*
,
void
*
);
typedef
unsigned
int
(
*
tdb1_hash_func
)(
TDB
1
_DATA
*
key
);
typedef
unsigned
int
(
*
tdb1_hash_func
)(
TDB_DATA
*
key
);
struct
tdb1_logging_context
{
tdb1_log_func
log_fn
;
...
...
@@ -84,30 +74,30 @@ struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flag
void
tdb1_set_max_dead
(
struct
tdb1_context
*
tdb
,
int
max_dead
);
TDB
1_DATA
tdb1_fetch
(
struct
tdb1_context
*
tdb
,
TDB1
_DATA
key
);
TDB
_DATA
tdb1_fetch
(
struct
tdb1_context
*
tdb
,
TDB
_DATA
key
);
int
tdb1_parse_record
(
struct
tdb1_context
*
tdb
,
TDB
1
_DATA
key
,
int
(
*
parser
)(
TDB
1_DATA
key
,
TDB1
_DATA
data
,
int
tdb1_parse_record
(
struct
tdb1_context
*
tdb
,
TDB_DATA
key
,
int
(
*
parser
)(
TDB
_DATA
key
,
TDB
_DATA
data
,
void
*
private_data
),
void
*
private_data
);
int
tdb1_delete
(
struct
tdb1_context
*
tdb
,
TDB
1
_DATA
key
);
int
tdb1_delete
(
struct
tdb1_context
*
tdb
,
TDB_DATA
key
);
int
tdb1_store
(
struct
tdb1_context
*
tdb
,
TDB
1_DATA
key
,
TDB1
_DATA
dbuf
,
int
flag
);
int
tdb1_store
(
struct
tdb1_context
*
tdb
,
TDB
_DATA
key
,
TDB
_DATA
dbuf
,
int
flag
);
int
tdb1_append
(
struct
tdb1_context
*
tdb
,
TDB
1_DATA
key
,
TDB1
_DATA
new_dbuf
);
int
tdb1_append
(
struct
tdb1_context
*
tdb
,
TDB
_DATA
key
,
TDB
_DATA
new_dbuf
);
int
tdb1_close
(
struct
tdb1_context
*
tdb
);
TDB
1
_DATA
tdb1_firstkey
(
struct
tdb1_context
*
tdb
);
TDB_DATA
tdb1_firstkey
(
struct
tdb1_context
*
tdb
);
TDB
1_DATA
tdb1_nextkey
(
struct
tdb1_context
*
tdb
,
TDB1
_DATA
key
);
TDB
_DATA
tdb1_nextkey
(
struct
tdb1_context
*
tdb
,
TDB
_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
,
TDB
1
_DATA
key
);
int
tdb1_exists
(
struct
tdb1_context
*
tdb
,
TDB_DATA
key
);
int
tdb1_lockall
(
struct
tdb1_context
*
tdb
);
...
...
@@ -131,19 +121,19 @@ int tdb1_hash_size(struct tdb1_context *tdb);
void
tdb1_increment_seqnum_nonblock
(
struct
tdb1_context
*
tdb
);
unsigned
int
tdb1_jenkins_hash
(
TDB
1
_DATA
*
key
);
unsigned
int
tdb1_jenkins_hash
(
TDB_DATA
*
key
);
int
tdb1_check
(
struct
tdb1_context
*
tdb
,
int
(
*
check
)
(
TDB
1_DATA
key
,
TDB1
_DATA
data
,
void
*
private_data
),
int
(
*
check
)
(
TDB
_DATA
key
,
TDB
_DATA
data
,
void
*
private_data
),
void
*
private_data
);
/* @} ******************************************************************/
/* Low level locking functions: use with care */
int
tdb1_chainlock
(
struct
tdb1_context
*
tdb
,
TDB
1
_DATA
key
);
int
tdb1_chainunlock
(
struct
tdb1_context
*
tdb
,
TDB
1
_DATA
key
);
int
tdb1_chainlock_read
(
struct
tdb1_context
*
tdb
,
TDB
1
_DATA
key
);
int
tdb1_chainunlock_read
(
struct
tdb1_context
*
tdb
,
TDB
1
_DATA
key
);
int
tdb1_chainlock
(
struct
tdb1_context
*
tdb
,
TDB_DATA
key
);
int
tdb1_chainunlock
(
struct
tdb1_context
*
tdb
,
TDB_DATA
key
);
int
tdb1_chainlock_read
(
struct
tdb1_context
*
tdb
,
TDB_DATA
key
);
int
tdb1_chainunlock_read
(
struct
tdb1_context
*
tdb
,
TDB_DATA
key
);
/* wipe and repack */
...
...
@@ -153,6 +143,6 @@ int tdb1_repack(struct tdb1_context *tdb);
/* Debug functions. Not used in production. */
char
*
tdb1_summary
(
struct
tdb1_context
*
tdb
);
extern
TDB
1
_DATA
tdb1_null
;
extern
TDB_DATA
tdb1_null
;
#endif
/* tdb1.h */
ccan/tdb2/tdb1_check.c
View file @
8a47d50d
...
...
@@ -32,7 +32,7 @@ static bool tdb1_check_header(struct tdb1_context *tdb, tdb1_off_t *recovery)
if
(
tdb
->
methods
->
tdb1_read
(
tdb
,
0
,
&
hdr
,
sizeof
(
hdr
),
0
)
==
-
1
)
return
false
;
if
(
strcmp
(
hdr
.
magic_food
,
TDB
1
_MAGIC_FOOD
)
!=
0
)
if
(
strcmp
(
hdr
.
magic_food
,
TDB_MAGIC_FOOD
)
!=
0
)
goto
corrupt
;
TDB1_CONV
(
hdr
);
...
...
@@ -132,10 +132,10 @@ corrupt:
/* Grab some bytes: may copy if can't use mmap.
Caller has already done bounds check. */
static
TDB
1
_DATA
get_bytes
(
struct
tdb1_context
*
tdb
,
static
TDB_DATA
get_bytes
(
struct
tdb1_context
*
tdb
,
tdb1_off_t
off
,
tdb1_len_t
len
)
{
TDB
1
_DATA
d
;
TDB_DATA
d
;
d
.
dsize
=
len
;
...
...
@@ -147,7 +147,7 @@ static TDB1_DATA get_bytes(struct tdb1_context *tdb,
}
/* Frees data if we're not able to simply use mmap. */
static
void
put_bytes
(
struct
tdb1_context
*
tdb
,
TDB
1
_DATA
d
)
static
void
put_bytes
(
struct
tdb1_context
*
tdb
,
TDB_DATA
d
)
{
if
(
tdb
->
transaction
==
NULL
&&
tdb
->
map_ptr
!=
NULL
)
return
;
...
...
@@ -236,10 +236,10 @@ static bool tdb1_check_used_record(struct tdb1_context *tdb,
tdb1_off_t
off
,
const
struct
tdb1_record
*
rec
,
unsigned
char
**
hashes
,
int
(
*
check
)(
TDB
1_DATA
,
TDB1
_DATA
,
void
*
),
int
(
*
check
)(
TDB
_DATA
,
TDB
_DATA
,
void
*
),
void
*
private_data
)
{
TDB
1
_DATA
key
,
data
;
TDB_DATA
key
,
data
;
if
(
!
tdb1_check_record
(
tdb
,
off
,
rec
))
return
false
;
...
...
@@ -323,7 +323,7 @@ size_t tdb1_dead_space(struct tdb1_context *tdb, tdb1_off_t off)
}
int
tdb1_check
(
struct
tdb1_context
*
tdb
,
int
(
*
check
)(
TDB
1_DATA
key
,
TDB1
_DATA
data
,
void
*
private_data
),
int
(
*
check
)(
TDB
_DATA
key
,
TDB
_DATA
data
,
void
*
private_data
),
void
*
private_data
)
{
unsigned
int
h
;
...
...
ccan/tdb2/tdb1_hash.c
View file @
8a47d50d
...
...
@@ -25,7 +25,7 @@
#include "tdb1_private.h"
/* This is based on the hash algorithm from gdbm */
unsigned
int
tdb1_old_hash
(
TDB
1
_DATA
*
key
)
unsigned
int
tdb1_old_hash
(
TDB_DATA
*
key
)
{
uint32_t
value
;
/* Used to compute the hash value. */
uint32_t
i
;
/* Used to cycle through random values. */
...
...
@@ -339,7 +339,7 @@ static uint32_t hashlittle( const void *key, size_t length )
return
c
;
}
unsigned
int
tdb1_jenkins_hash
(
TDB
1
_DATA
*
key
)
unsigned
int
tdb1_jenkins_hash
(
TDB_DATA
*
key
)
{
return
hashlittle
(
key
->
dptr
,
key
->
dsize
);
}
ccan/tdb2/tdb1_io.c
View file @
8a47d50d
...
...
@@ -427,13 +427,13 @@ unsigned char *tdb1_alloc_read(struct tdb1_context *tdb, tdb1_off_t offset, tdb1
/* Give a piece of tdb data to a parser */
int
tdb1_parse_data
(
struct
tdb1_context
*
tdb
,
TDB
1
_DATA
key
,
int
tdb1_parse_data
(
struct
tdb1_context
*
tdb
,
TDB_DATA
key
,
tdb1_off_t
offset
,
tdb1_len_t
len
,
int
(
*
parser
)(
TDB
1_DATA
key
,
TDB1
_DATA
data
,
int
(
*
parser
)(
TDB
_DATA
key
,
TDB
_DATA
data
,
void
*
private_data
),
void
*
private_data
)
{
TDB
1
_DATA
data
;
TDB_DATA
data
;
int
result
;
data
.
dsize
=
len
;
...
...
ccan/tdb2/tdb1_lock.c
View file @
8a47d50d
...
...
@@ -130,7 +130,7 @@ static tdb1_off_t lock_offset(int list)
*/
int
tdb1_brlock
(
struct
tdb1_context
*
tdb
,
int
rw_type
,
tdb1_off_t
offset
,
size_t
len
,
enum
tdb
1
_lock_flags
flags
)
enum
tdb_lock_flags
flags
)
{
int
ret
;
...
...
@@ -145,7 +145,7 @@ int tdb1_brlock(struct tdb1_context *tdb,
do
{
ret
=
fcntl_lock
(
tdb
,
rw_type
,
offset
,
len
,
flags
&
TDB
1
_LOCK_WAIT
);
flags
&
TDB_LOCK_WAIT
);
}
while
(
ret
==
-
1
&&
errno
==
EINTR
);
if
(
ret
==
-
1
)
{
...
...
@@ -153,7 +153,7 @@ int tdb1_brlock(struct tdb1_context *tdb,
/* Generic lock error. errno set by fcntl.
* EAGAIN is an expected return from non-blocking
* locks. */
if
(
!
(
flags
&
TDB
1
_LOCK_PROBE
)
&&
errno
!=
EAGAIN
)
{
if
(
!
(
flags
&
TDB_LOCK_PROBE
)
&&
errno
!=
EAGAIN
)
{
tdb_logerr
(
tdb
,
TDB_ERR_LOCK
,
TDB_LOG_ERROR
,
"tdb1_brlock failed (fd=%d) at offset %d rw_type=%d flags=%d len=%d"
,
tdb
->
fd
,
offset
,
rw_type
,
flags
,
(
int
)
len
);
...
...
@@ -213,7 +213,7 @@ int tdb1_allrecord_upgrade(struct tdb1_context *tdb)
while
(
count
--
)
{
struct
timeval
tv
;
if
(
tdb1_brlock
(
tdb
,
F_WRLCK
,
TDB1_FREELIST_TOP
,
0
,
TDB
1_LOCK_WAIT
|
TDB1
_LOCK_PROBE
)
==
0
)
{
TDB
_LOCK_WAIT
|
TDB
_LOCK_PROBE
)
==
0
)
{
tdb
->
allrecord_lock
.
ltype
=
F_WRLCK
;
tdb
->
allrecord_lock
.
off
=
0
;
return
0
;
...
...
@@ -246,7 +246,7 @@ static struct tdb1_lock_type *tdb1_find_nestlock(struct tdb1_context *tdb,
/* lock an offset in the database. */
int
tdb1_nest_lock
(
struct
tdb1_context
*
tdb
,
uint32_t
offset
,
int
ltype
,
enum
tdb
1
_lock_flags
flags
)
enum
tdb_lock_flags
flags
)
{
struct
tdb1_lock_type
*
new_lck
;
...
...
@@ -298,11 +298,11 @@ static int tdb1_lock_and_recover(struct tdb1_context *tdb)
int
ret
;
/* We need to match locking order in transaction commit. */
if
(
tdb1_brlock
(
tdb
,
F_WRLCK
,
TDB1_FREELIST_TOP
,
0
,
TDB
1
_LOCK_WAIT
))
{
if
(
tdb1_brlock
(
tdb
,
F_WRLCK
,
TDB1_FREELIST_TOP
,
0
,
TDB_LOCK_WAIT
))
{
return
-
1
;
}
if
(
tdb1_brlock
(
tdb
,
F_WRLCK
,
TDB1_OPEN_LOCK
,
1
,
TDB
1
_LOCK_WAIT
))
{
if
(
tdb1_brlock
(
tdb
,
F_WRLCK
,
TDB1_OPEN_LOCK
,
1
,
TDB_LOCK_WAIT
))
{
tdb1_brunlock
(
tdb
,
F_WRLCK
,
TDB1_FREELIST_TOP
,
0
);
return
-
1
;
}
...
...
@@ -327,7 +327,7 @@ static bool have_data_locks(const struct tdb1_context *tdb)
}
static
int
tdb1_lock_list
(
struct
tdb1_context
*
tdb
,
int
list
,
int
ltype
,
enum
tdb
1
_lock_flags
waitflag
)
enum
tdb_lock_flags
waitflag
)
{
int
ret
;
bool
check
=
false
;
...
...
@@ -363,7 +363,7 @@ int tdb1_lock(struct tdb1_context *tdb, int list, int ltype)
{
int
ret
;
ret
=
tdb1_lock_list
(
tdb
,
list
,
ltype
,
TDB
1
_LOCK_WAIT
);
ret
=
tdb1_lock_list
(
tdb
,
list
,
ltype
,
TDB_LOCK_WAIT
);
if
(
ret
)
{
tdb_logerr
(
tdb
,
tdb
->
last_error
,
TDB_LOG_ERROR
,
"tdb1_lock failed on list %d "
...
...
@@ -447,7 +447,7 @@ int tdb1_unlock(struct tdb1_context *tdb, int list, int ltype)
get the transaction lock
*/
int
tdb1_transaction_lock
(
struct
tdb1_context
*
tdb
,
int
ltype
,
enum
tdb
1
_lock_flags
lockflags
)
enum
tdb_lock_flags
lockflags
)
{
return
tdb1_nest_lock
(
tdb
,
TDB1_TRANSACTION_LOCK
,
ltype
,
lockflags
);
}
...
...
@@ -462,7 +462,7 @@ int tdb1_transaction_unlock(struct tdb1_context *tdb, int ltype)
/* Returns 0 if all done, -1 if error, 1 if ok. */
static
int
tdb1_allrecord_check
(
struct
tdb1_context
*
tdb
,
int
ltype
,
enum
tdb
1
_lock_flags
flags
,
bool
upgradable
)
enum
tdb_lock_flags
flags
,
bool
upgradable
)
{
/* There are no locks on read-only dbs */
if
(
tdb
->
read_only
||
tdb
->
traverse_read
)
{
...
...
@@ -498,11 +498,11 @@ static int tdb1_allrecord_check(struct tdb1_context *tdb, int ltype,
/* We only need to lock individual bytes, but Linux merges consecutive locks
* so we lock in contiguous ranges. */
static
int
tdb1_chainlock_gradual
(
struct
tdb1_context
*
tdb
,
int
ltype
,
enum
tdb
1
_lock_flags
flags
,
int
ltype
,
enum
tdb_lock_flags
flags
,
size_t
off
,
size_t
len
)
{
int
ret
;
enum
tdb
1_lock_flags
nb_flags
=
(
flags
&
~
TDB1
_LOCK_WAIT
);
enum
tdb
_lock_flags
nb_flags
=
(
flags
&
~
TDB
_LOCK_WAIT
);
if
(
len
<=
4
)
{
/* Single record. Just do blocking lock. */
...
...
@@ -533,7 +533,7 @@ static int tdb1_chainlock_gradual(struct tdb1_context *tdb,
* other way of guaranteeing exclusivity (ie. transaction write lock).
* We do the locking gradually to avoid being starved by smaller locks. */
int
tdb1_allrecord_lock
(
struct
tdb1_context
*
tdb
,
int
ltype
,
enum
tdb
1
_lock_flags
flags
,
bool
upgradable
)
enum
tdb_lock_flags
flags
,
bool
upgradable
)
{
switch
(
tdb1_allrecord_check
(
tdb
,
ltype
,
flags
,
upgradable
))
{
case
-
1
:
...
...
@@ -622,7 +622,7 @@ int tdb1_allrecord_unlock(struct tdb1_context *tdb, int ltype)
/* lock entire database with write lock */
int
tdb1_lockall
(
struct
tdb1_context
*
tdb
)
{
return
tdb1_allrecord_lock
(
tdb
,
F_WRLCK
,
TDB
1
_LOCK_WAIT
,
false
);
return
tdb1_allrecord_lock
(
tdb
,
F_WRLCK
,
TDB_LOCK_WAIT
,
false
);
}
/* unlock entire database with write lock */
...
...
@@ -634,7 +634,7 @@ int tdb1_unlockall(struct tdb1_context *tdb)
/* lock entire database with read lock */
int
tdb1_lockall_read
(
struct
tdb1_context
*
tdb
)
{
return
tdb1_allrecord_lock
(
tdb
,
F_RDLCK
,
TDB
1
_LOCK_WAIT
,
false
);
return
tdb1_allrecord_lock
(
tdb
,
F_RDLCK
,
TDB_LOCK_WAIT
,
false
);
}
/* unlock entire database with read lock */
...
...
@@ -645,25 +645,25 @@ int tdb1_unlockall_read(struct tdb1_context *tdb)
/* lock/unlock one hash chain. This is meant to be used to reduce
contention - it cannot guarantee how many records will be locked */
int
tdb1_chainlock
(
struct
tdb1_context
*
tdb
,
TDB
1
_DATA
key
)
int
tdb1_chainlock
(
struct
tdb1_context
*
tdb
,
TDB_DATA
key
)
{
int
ret
=
tdb1_lock
(
tdb
,
TDB1_BUCKET
(
tdb
->
hash_fn
(
&
key
)),
F_WRLCK
);
return
ret
;
}
int
tdb1_chainunlock
(
struct
tdb1_context
*
tdb
,
TDB
1
_DATA
key
)
int
tdb1_chainunlock
(
struct
tdb1_context
*
tdb
,
TDB_DATA
key
)
{
return
tdb1_unlock
(
tdb
,
TDB1_BUCKET
(
tdb
->
hash_fn
(
&
key
)),
F_WRLCK
);
}
int
tdb1_chainlock_read
(
struct
tdb1_context
*
tdb
,
TDB
1
_DATA
key
)
int
tdb1_chainlock_read
(
struct
tdb1_context
*
tdb
,
TDB_DATA
key
)
{
int
ret
;
ret
=
tdb1_lock
(
tdb
,
TDB1_BUCKET
(
tdb
->
hash_fn
(
&
key
)),
F_RDLCK
);
return
ret
;
}
int
tdb1_chainunlock_read
(
struct
tdb1_context
*
tdb
,
TDB
1
_DATA
key
)
int
tdb1_chainunlock_read
(
struct
tdb1_context
*
tdb
,
TDB_DATA
key
)
{
return
tdb1_unlock
(
tdb
,
TDB1_BUCKET
(
tdb
->
hash_fn
(
&
key
)),
F_RDLCK
);
}
...
...
@@ -674,7 +674,7 @@ int tdb1_lock_record(struct tdb1_context *tdb, tdb1_off_t off)
if
(
tdb
->
allrecord_lock
.
count
)
{
return
0
;
}
return
off
?
tdb1_brlock
(
tdb
,
F_RDLCK
,
off
,
1
,
TDB
1
_LOCK_WAIT
)
:
0
;
return
off
?
tdb1_brlock
(
tdb
,
F_RDLCK
,
off
,
1
,
TDB_LOCK_WAIT
)
:
0
;
}
/*
...
...
@@ -694,7 +694,7 @@ int tdb1_write_lock_record(struct tdb1_context *tdb, tdb1_off_t off)
}
return
-
1
;
}
return
tdb1_brlock
(
tdb
,
F_WRLCK
,
off
,
1
,
TDB
1_LOCK_NOWAIT
|
TDB1
_LOCK_PROBE
);
return
tdb1_brlock
(
tdb
,
F_WRLCK
,
off
,
1
,
TDB
_LOCK_NOWAIT
|
TDB
_LOCK_PROBE
);
}
int
tdb1_write_unlock_record
(
struct
tdb1_context
*
tdb
,
tdb1_off_t
off
)
...
...
ccan/tdb2/tdb1_open.c
View file @
8a47d50d
...
...
@@ -34,11 +34,11 @@ static struct tdb1_context *tdb1s = NULL;
void
tdb1_header_hash
(
struct
tdb1_context
*
tdb
,
uint32_t
*
magic1_hash
,
uint32_t
*
magic2_hash
)
{
TDB
1
_DATA
hash_key
;
TDB_DATA
hash_key
;
uint32_t
tdb1_magic
=
TDB1_MAGIC
;
hash_key
.
dptr
=
(
unsigned
char
*
)
TDB
1
_MAGIC_FOOD
;
hash_key
.
dsize
=
sizeof
(
TDB
1
_MAGIC_FOOD
);
hash_key
.
dptr
=
(
unsigned
char
*
)
TDB_MAGIC_FOOD
;
hash_key
.
dsize
=
sizeof
(
TDB_MAGIC_FOOD
);
*
magic1_hash
=
tdb
->
hash_fn
(
&
hash_key
);
hash_key
.
dptr
=
(
unsigned
char
*
)
TDB1_CONV
(
tdb1_magic
);
...
...
@@ -93,7 +93,7 @@ static int tdb1_new_database(struct tdb1_context *tdb, int hash_size)
TDB1_CONV
(
*
newdb
);
memcpy
(
&
tdb
->
header
,
newdb
,
sizeof
(
tdb
->
header
));
/* Don't endian-convert the magic food! */
memcpy
(
newdb
->
magic_food
,
TDB
1_MAGIC_FOOD
,
strlen
(
TDB1
_MAGIC_FOOD
)
+
1
);
memcpy
(
newdb
->
magic_food
,
TDB
_MAGIC_FOOD
,
strlen
(
TDB
_MAGIC_FOOD
)
+
1
);
/* we still have "ret == -1" here */
if
(
tdb1_write_all
(
tdb
->
fd
,
newdb
,
size
))
ret
=
0
;
...
...
@@ -293,7 +293,7 @@ struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flag
fcntl
(
tdb
->
fd
,
F_SETFD
,
v
|
FD_CLOEXEC
);
/* ensure there is only one process initialising at once */
if
(
tdb1_nest_lock
(
tdb
,
TDB1_OPEN_LOCK
,
F_WRLCK
,
TDB
1
_LOCK_WAIT
)
==
-
1
)
{
if
(
tdb1_nest_lock
(
tdb
,
TDB1_OPEN_LOCK
,
F_WRLCK
,
TDB_LOCK_WAIT
)
==
-
1
)
{
tdb_logerr
(
tdb
,
tdb
->
last_error
,
TDB_LOG_ERROR
,
"tdb1_open_ex: failed to get open lock on %s: %s"
,
name
,
strerror
(
errno
));
...
...
@@ -303,7 +303,7 @@ struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flag
/* we need to zero database if we are the only one with it open */
if
((
tdb1_flags
&
TDB1_CLEAR_IF_FIRST
)
&&
(
!
tdb
->
read_only
)
&&
(
locked
=
(
tdb1_nest_lock
(
tdb
,
TDB1_ACTIVE_LOCK
,
F_WRLCK
,
TDB
1_LOCK_NOWAIT
|
TDB1
_LOCK_PROBE
)
==
0
)))
{
(
locked
=
(
tdb1_nest_lock
(
tdb
,
TDB1_ACTIVE_LOCK
,
F_WRLCK
,
TDB
_LOCK_NOWAIT
|
TDB
_LOCK_PROBE
)
==
0
)))
{
open_flags
|=
O_CREAT
;
if
(
ftruncate
(
tdb
->
fd
,
0
)
==
-
1
)
{
tdb_logerr
(
tdb
,
TDB_ERR_IO
,
TDB_LOG_ERROR
,
...
...
@@ -316,7 +316,7 @@ struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flag
errno
=
0
;
if
(
read
(
tdb
->
fd
,
&
tdb
->
header
,
sizeof
(
tdb
->
header
))
!=
sizeof
(
tdb
->
header
)
||
strcmp
(
tdb
->
header
.
magic_food
,
TDB
1
_MAGIC_FOOD
)
!=
0
)
{
||
strcmp
(
tdb
->
header
.
magic_food
,
TDB_MAGIC_FOOD
)
!=
0
)
{
if
(
!
(
open_flags
&
O_CREAT
)
||
tdb1_new_database
(
tdb
,
hash_size
)
==
-
1
)
{
if
(
errno
==
0
)
{
errno
=
EIO
;
/* ie bad format or something */
...
...
@@ -401,7 +401,7 @@ struct tdb1_context *tdb1_open_ex(const char *name, int hash_size, int tdb1_flag
if
(
tdb1_flags
&
TDB1_CLEAR_IF_FIRST
)
{
/* leave this lock in place to indicate it's in use */
if
(
tdb1_nest_lock
(
tdb
,
TDB1_ACTIVE_LOCK
,
F_RDLCK
,
TDB
1
_LOCK_WAIT
)
==
-
1
)
{
if
(
tdb1_nest_lock
(
tdb
,
TDB1_ACTIVE_LOCK
,
F_RDLCK
,
TDB_LOCK_WAIT
)
==
-
1
)
{
goto
fail
;
}
}
...
...
ccan/tdb2/tdb1_private.h
View file @
8a47d50d
...
...
@@ -63,7 +63,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)
...
...
@@ -131,7 +130,7 @@ 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 TDB
1
_MAGIC_FOOD. */
uint32_t
magic1_hash
;
/* hash of TDB_MAGIC_FOOD. */
uint32_t
magic2_hash
;
/* hash of TDB1_MAGIC. */
tdb1_off_t
reserved
[
27
];
};
...
...
@@ -149,14 +148,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
{
...
...
@@ -197,7 +188,7 @@ struct tdb1_context {
struct
tdb1_traverse_lock
travlocks
;
/* current traversal locks */
dev_t
device
;
/* uniquely identifies this tdb */
ino_t
inode
;
/* uniquely identifies this tdb */
unsigned
int
(
*
hash_fn
)(
TDB
1
_DATA
*
key
);
unsigned
int
(
*
hash_fn
)(
TDB_DATA
*
key
);
int
open_flags
;
/* flags used in the open - needed by reopen */
const
struct
tdb1_methods
*
methods
;
struct
tdb1_transaction
*
transaction
;
...
...
@@ -212,25 +203,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
tdb
1
_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
tdb
1
_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
tdb
1
_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
tdb
1
_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
);
...
...
@@ -249,12 +240,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
,
TDB
1
_DATA
key
,
int
tdb1_parse_data
(
struct
tdb1_context
*
tdb
,
TDB_DATA
key
,
tdb1_off_t
offset
,
tdb1_len_t
len
,
int
(
*
parser
)(
TDB
1_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
,
TDB
1
_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
);
...
...
@@ -264,6 +255,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
(
TDB
1
_DATA
*
key
);
unsigned
int
tdb1_old_hash
(
TDB_DATA
*
key
);
size_t
tdb1_dead_space
(
struct
tdb1_context
*
tdb
,
tdb1_off_t
off
);
#endif
/* CCAN_TDB2_TDB1_PRIVATE_H */
ccan/tdb2/tdb1_tdb.c
View file @
8a47d50d
...
...
@@ -27,7 +27,7 @@
#include "tdb1_private.h"
TDB
1
_DATA
tdb1_null
;
TDB_DATA
tdb1_null
;
/*
non-blocking increment of the tdb sequence number if the tdb has been opened using
...
...
@@ -60,7 +60,7 @@ static void tdb1_increment_seqnum(struct tdb1_context *tdb)
}
if
(
tdb1_nest_lock
(
tdb
,
TDB1_SEQNUM_OFS
,
F_WRLCK
,
TDB1_LOCK_WAIT
|
TDB1
_LOCK_PROBE
)
!=
0
)
{
TDB_LOCK_WAIT
|
TDB
_LOCK_PROBE
)
!=
0
)
{
return
;
}
...
...
@@ -69,14 +69,14 @@ static void tdb1_increment_seqnum(struct tdb1_context *tdb)
tdb1_nest_unlock
(
tdb
,
TDB1_SEQNUM_OFS
,
F_WRLCK
);
}
static
int
tdb1_key_compare
(
TDB
1_DATA
key
,
TDB1
_DATA
data
,
void
*
private_data
)
static
int
tdb1_key_compare
(
TDB
_DATA
key
,
TDB
_DATA
data
,
void
*
private_data
)
{
return
memcmp
(
data
.
dptr
,
key
.
dptr
,
data
.
dsize
);
}
/* Returns 0 on fail. On success, return offset of record, and fills
in rec */
static
tdb1_off_t
tdb1_find
(
struct
tdb1_context
*
tdb
,
TDB
1
_DATA
key
,
uint32_t
hash
,
static
tdb1_off_t
tdb1_find
(
struct
tdb1_context
*
tdb
,
TDB_DATA
key
,
uint32_t
hash
,
struct
tdb1_record
*
r
)
{
tdb1_off_t
rec_ptr
;
...
...
@@ -111,7 +111,7 @@ static tdb1_off_t tdb1_find(struct tdb1_context *tdb, TDB1_DATA key, uint32_t ha
}
/* As tdb1_find, but if you succeed, keep the lock */
tdb1_off_t
tdb1_find_lock_hash
(
struct
tdb1_context
*
tdb
,
TDB
1
_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
)
{
uint32_t
rec_ptr
;
...
...
@@ -123,13 +123,13 @@ tdb1_off_t tdb1_find_lock_hash(struct tdb1_context *tdb, TDB1_DATA key, uint32_t
return
rec_ptr
;
}
static
TDB
1_DATA
_tdb1_fetch
(
struct
tdb1_context
*
tdb
,
TDB1
_DATA
key
);
static
TDB
_DATA
_tdb1_fetch
(
struct
tdb1_context
*
tdb
,
TDB
_DATA
key
);
/* update an entry in place - this only works if the new data size
is <= the old data size and the key exists.
on failure return -1.
*/
static
int
tdb1_update_hash
(
struct
tdb1_context
*
tdb
,
TDB
1_DATA
key
,
uint32_t
hash
,
TDB1
_DATA
dbuf
)
static
int
tdb1_update_hash
(
struct
tdb1_context
*
tdb
,
TDB
_DATA
key
,
uint32_t
hash
,
TDB
_DATA
dbuf
)
{
struct
tdb1_record
rec
;
tdb1_off_t
rec_ptr
;
...
...
@@ -143,7 +143,7 @@ static int tdb1_update_hash(struct tdb1_context *tdb, TDB1_DATA key, uint32_t ha
if
(
rec
.
key_len
==
key
.
dsize
&&
rec
.
data_len
==
dbuf
.
dsize
&&
rec
.
full_hash
==
hash
)
{
TDB
1
_DATA
data
=
_tdb1_fetch
(
tdb
,
key
);
TDB_DATA
data
=
_tdb1_fetch
(
tdb
,
key
);
if
(
data
.
dsize
==
dbuf
.
dsize
&&
memcmp
(
data
.
dptr
,
dbuf
.
dptr
,
data
.
dsize
)
==
0
)
{
if
(
data
.
dptr
)
{
...
...
@@ -178,14 +178,14 @@ static int tdb1_update_hash(struct tdb1_context *tdb, TDB1_DATA key, uint32_t ha
/* find an entry in the database given a key */
/* If an entry doesn't exist tdb1_err will be set to
* TDB_ERR_NOEXIST. If a key has no data attached
* then the TDB
1
_DATA will have zero length but
* then the TDB_DATA will have zero length but
* a non-zero pointer
*/
static
TDB
1_DATA
_tdb1_fetch
(
struct
tdb1_context
*
tdb
,
TDB1
_DATA
key
)
static
TDB
_DATA
_tdb1_fetch
(
struct
tdb1_context
*
tdb
,
TDB
_DATA
key
)
{
tdb1_off_t
rec_ptr
;
struct
tdb1_record
rec
;
TDB
1
_DATA
ret
;
TDB_DATA
ret
;
uint32_t
hash
;
/* find which hash bucket it is in */
...
...
@@ -200,9 +200,9 @@ static TDB1_DATA _tdb1_fetch(struct tdb1_context *tdb, TDB1_DATA key)
return
ret
;
}
TDB
1_DATA
tdb1_fetch
(
struct
tdb1_context
*
tdb
,
TDB1
_DATA
key
)
TDB
_DATA
tdb1_fetch
(
struct
tdb1_context
*
tdb
,
TDB
_DATA
key
)
{
TDB
1
_DATA
ret
=
_tdb1_fetch
(
tdb
,
key
);
TDB_DATA
ret
=
_tdb1_fetch
(
tdb
,
key
);
return
ret
;
}
...
...
@@ -225,8 +225,8 @@ TDB1_DATA tdb1_fetch(struct tdb1_context *tdb, TDB1_DATA key)
* Return -1 if the record was not found.
*/
int
tdb1_parse_record
(
struct
tdb1_context
*
tdb
,
TDB
1
_DATA
key
,
int
(
*
parser
)(
TDB
1_DATA
key
,
TDB1
_DATA
data
,
int
tdb1_parse_record
(
struct
tdb1_context
*
tdb
,
TDB_DATA
key
,
int
(
*
parser
)(
TDB
_DATA
key
,
TDB
_DATA
data
,
void
*
private_data
),
void
*
private_data
)
{
...
...
@@ -258,7 +258,7 @@ int tdb1_parse_record(struct tdb1_context *tdb, TDB1_DATA key,
this doesn't match the conventions in the rest of this module, but is
compatible with gdbm
*/
static
int
tdb1_exists_hash
(
struct
tdb1_context
*
tdb
,
TDB
1
_DATA
key
,
uint32_t
hash
)
static
int
tdb1_exists_hash
(
struct
tdb1_context
*
tdb
,
TDB_DATA
key
,
uint32_t
hash
)
{
struct
tdb1_record
rec
;
...
...
@@ -268,7 +268,7 @@ static int tdb1_exists_hash(struct tdb1_context *tdb, TDB1_DATA key, uint32_t ha
return
1
;
}
int
tdb1_exists
(
struct
tdb1_context
*
tdb
,
TDB
1
_DATA
key
)
int
tdb1_exists
(
struct
tdb1_context
*
tdb
,
TDB_DATA
key
)
{
uint32_t
hash
=
tdb
->
hash_fn
(
&
key
);
int
ret
;
...
...
@@ -374,7 +374,7 @@ static int tdb1_purge_dead(struct tdb1_context *tdb, uint32_t hash)
}
/* delete an entry in the database given a key */
static
int
tdb1_delete_hash
(
struct
tdb1_context
*
tdb
,
TDB
1
_DATA
key
,
uint32_t
hash
)
static
int
tdb1_delete_hash
(
struct
tdb1_context
*
tdb
,
TDB_DATA
key
,
uint32_t
hash
)
{
tdb1_off_t
rec_ptr
;
struct
tdb1_record
rec
;
...
...
@@ -427,7 +427,7 @@ static int tdb1_delete_hash(struct tdb1_context *tdb, TDB1_DATA key, uint32_t ha
return
ret
;
}
int
tdb1_delete
(
struct
tdb1_context
*
tdb
,
TDB
1
_DATA
key
)
int
tdb1_delete
(
struct
tdb1_context
*
tdb
,
TDB_DATA
key
)
{
uint32_t
hash
=
tdb
->
hash_fn
(
&
key
);
int
ret
;
...
...
@@ -465,8 +465,8 @@ static tdb1_off_t tdb1_find_dead(struct tdb1_context *tdb, uint32_t hash,
return
0
;
}
static
int
_tdb1_store
(
struct
tdb1_context
*
tdb
,
TDB
1
_DATA
key
,
TDB
1
_DATA
dbuf
,
int
flag
,
uint32_t
hash
)
static
int
_tdb1_store
(
struct
tdb1_context
*
tdb
,
TDB_DATA
key
,
TDB_DATA
dbuf
,
int
flag
,
uint32_t
hash
)
{
struct
tdb1_record
rec
;
tdb1_off_t
rec_ptr
;
...
...
@@ -474,7 +474,7 @@ static int _tdb1_store(struct tdb1_context *tdb, TDB1_DATA key,
int
ret
=
-
1
;
/* check for it existing, on insert. */
if
(
flag
==
TDB
1
_INSERT
)
{
if
(
flag
==
TDB_INSERT
)
{
if
(
tdb1_exists_hash
(
tdb
,
key
,
hash
))
{
tdb
->
last_error
=
TDB_ERR_EXISTS
;
goto
fail
;
...
...
@@ -485,7 +485,7 @@ static int _tdb1_store(struct tdb1_context *tdb, TDB1_DATA key,
goto
done
;
}
if
(
tdb
->
last_error
==
TDB_ERR_NOEXIST
&&
flag
==
TDB
1
_MODIFY
)
{
flag
==
TDB_MODIFY
)
{
/* if the record doesn't exist and we are in TDB1_MODIFY mode then
we should fail the store */
goto
fail
;
...
...
@@ -497,7 +497,7 @@ static int _tdb1_store(struct tdb1_context *tdb, TDB1_DATA key,
/* delete any existing record - if it doesn't exist we don't
care. Doing this first reduces fragmentation, and avoids
coalescing with `allocated' block before it's updated. */
if
(
flag
!=
TDB
1
_INSERT
)
if
(
flag
!=
TDB_INSERT
)
tdb1_delete_hash
(
tdb
,
key
,
hash
);
/* Copy key+value *before* allocating free space in case malloc
...
...
@@ -596,7 +596,7 @@ static int _tdb1_store(struct tdb1_context *tdb, TDB1_DATA key,
return 0 on success, -1 on failure
*/
int
tdb1_store
(
struct
tdb1_context
*
tdb
,
TDB
1_DATA
key
,
TDB1
_DATA
dbuf
,
int
flag
)
int
tdb1_store
(
struct
tdb1_context
*
tdb
,
TDB
_DATA
key
,
TDB
_DATA
dbuf
,
int
flag
)
{
uint32_t
hash
;
int
ret
;
...
...
@@ -617,10 +617,10 @@ int tdb1_store(struct tdb1_context *tdb, TDB1_DATA key, TDB1_DATA dbuf, int flag
}
/* Append to an entry. Create if not exist. */
int
tdb1_append
(
struct
tdb1_context
*
tdb
,
TDB
1_DATA
key
,
TDB1
_DATA
new_dbuf
)
int
tdb1_append
(
struct
tdb1_context
*
tdb
,
TDB
_DATA
key
,
TDB
_DATA
new_dbuf
)
{
uint32_t
hash
;
TDB
1
_DATA
dbuf
;
TDB_DATA
dbuf
;
int
ret
=
-
1
;
/* find which hash bucket it is in */
...
...
@@ -819,10 +819,10 @@ struct traverse_state {
/*
traverse function for repacking
*/
static
int
repack_traverse
(
struct
tdb1_context
*
tdb
,
TDB
1_DATA
key
,
TDB1
_DATA
data
,
void
*
private_data
)
static
int
repack_traverse
(
struct
tdb1_context
*
tdb
,
TDB
_DATA
key
,
TDB
_DATA
data
,
void
*
private_data
)
{
struct
traverse_state
*
state
=
(
struct
traverse_state
*
)
private_data
;
if
(
tdb1_store
(
state
->
dest_db
,
key
,
data
,
TDB
1
_INSERT
)
!=
0
)
{
if
(
tdb1_store
(
state
->
dest_db
,
key
,
data
,
TDB_INSERT
)
!=
0
)
{
state
->
error
=
state
->
dest_db
->
last_error
;
return
-
1
;
}
...
...
ccan/tdb2/tdb1_transaction.c
View file @
8a47d50d
...
...
@@ -478,7 +478,7 @@ static int _tdb1_transaction_start(struct tdb1_context *tdb)
/* get the transaction write lock. This is a blocking lock. As
discussed with Volker, there are a number of ways we could
make this async, which we will probably do in the future */
if
(
tdb1_transaction_lock
(
tdb
,
F_WRLCK
,
TDB
1
_LOCK_WAIT
)
==
-
1
)
{
if
(
tdb1_transaction_lock
(
tdb
,
F_WRLCK
,
TDB_LOCK_WAIT
)
==
-
1
)
{
SAFE_FREE
(
tdb
->
transaction
->
blocks
);
SAFE_FREE
(
tdb
->
transaction
);
return
-
1
;
...
...
@@ -486,7 +486,7 @@ static int _tdb1_transaction_start(struct tdb1_context *tdb)
/* get a read lock from the freelist to the end of file. This
is upgraded to a write lock during the commit */
if
(
tdb1_allrecord_lock
(
tdb
,
F_RDLCK
,
TDB
1
_LOCK_WAIT
,
true
)
==
-
1
)
{
if
(
tdb1_allrecord_lock
(
tdb
,
F_RDLCK
,
TDB_LOCK_WAIT
,
true
)
==
-
1
)
{
tdb_logerr
(
tdb
,
tdb
->
last_error
,
TDB_LOG_ERROR
,
"tdb1_transaction_start: failed to get hash locks"
);
goto
fail_allrecord_lock
;
...
...
@@ -973,7 +973,7 @@ static int _tdb1_transaction_prepare_commit(struct tdb1_context *tdb)
/* get the open lock - this prevents new users attaching to the database
during the commit */
if
(
tdb1_nest_lock
(
tdb
,
TDB1_OPEN_LOCK
,
F_WRLCK
,
TDB
1
_LOCK_WAIT
)
==
-
1
)
{
if
(
tdb1_nest_lock
(
tdb
,
TDB1_OPEN_LOCK
,
F_WRLCK
,
TDB_LOCK_WAIT
)
==
-
1
)
{
tdb_logerr
(
tdb
,
tdb
->
last_error
,
TDB_LOG_ERROR
,
"tdb1_transaction_prepare_commit:"
" failed to get open lock"
);
...
...
ccan/tdb2/tdb1_traverse.c
View file @
8a47d50d
...
...
@@ -147,7 +147,7 @@ static int tdb1_traverse_internal(struct tdb1_context *tdb,
tdb1_traverse_func
fn
,
void
*
private_data
,
struct
tdb1_traverse_lock
*
tl
)
{
TDB
1
_DATA
key
,
dbuf
;
TDB_DATA
key
,
dbuf
;
struct
tdb1_record
rec
;
int
ret
=
0
,
count
=
0
;
tdb1_off_t
off
;
...
...
@@ -223,7 +223,7 @@ int tdb1_traverse_read(struct tdb1_context *tdb,
/* we need to get a read lock on the transaction lock here to
cope with the lock ordering semantics of solaris10 */
if
(
tdb1_transaction_lock
(
tdb
,
F_RDLCK
,
TDB
1
_LOCK_WAIT
))
{
if
(
tdb1_transaction_lock
(
tdb
,
F_RDLCK
,
TDB_LOCK_WAIT
))
{
return
-
1
;
}
...
...
@@ -253,7 +253,7 @@ int tdb1_traverse(struct tdb1_context *tdb,
return
tdb1_traverse_read
(
tdb
,
fn
,
private_data
);
}
if
(
tdb1_transaction_lock
(
tdb
,
F_WRLCK
,
TDB
1
_LOCK_WAIT
))
{
if
(
tdb1_transaction_lock
(
tdb
,
F_WRLCK
,
TDB_LOCK_WAIT
))
{
return
-
1
;
}
...
...
@@ -268,9 +268,9 @@ int tdb1_traverse(struct tdb1_context *tdb,
/* find the first entry in the database and return its key */
TDB
1
_DATA
tdb1_firstkey
(
struct
tdb1_context
*
tdb
)
TDB_DATA
tdb1_firstkey
(
struct
tdb1_context
*
tdb
)
{
TDB
1
_DATA
key
;
TDB_DATA
key
;
struct
tdb1_record
rec
;
tdb1_off_t
off
;
...
...
@@ -298,10 +298,10 @@ TDB1_DATA tdb1_firstkey(struct tdb1_context *tdb)
}
/* find the next entry in the database, returning its key */
TDB
1_DATA
tdb1_nextkey
(
struct
tdb1_context
*
tdb
,
TDB1
_DATA
oldkey
)
TDB
_DATA
tdb1_nextkey
(
struct
tdb1_context
*
tdb
,
TDB
_DATA
oldkey
)
{
uint32_t
oldhash
;
TDB
1
_DATA
key
=
tdb1_null
;
TDB_DATA
key
=
tdb1_null
;
struct
tdb1_record
rec
;
unsigned
char
*
k
=
NULL
;
tdb1_off_t
off
;
...
...
ccan/tdb2/test/run-tdb1-3G-file.c
View file @
8a47d50d
...
...
@@ -46,10 +46,10 @@ static const struct tdb1_methods large_io_methods = {
tdb1_expand_file_sparse
};
static
int
test_traverse
(
struct
tdb1_context
*
tdb
,
TDB
1_DATA
key
,
TDB1
_DATA
data
,
static
int
test_traverse
(
struct
tdb1_context
*
tdb
,
TDB
_DATA
key
,
TDB
_DATA
data
,
void
*
_data
)
{
TDB
1
_DATA
*
expect
=
_data
;
TDB_DATA
*
expect
=
_data
;
ok1
(
key
.
dsize
==
strlen
(
"hi"
));
ok1
(
memcmp
(
key
.
dptr
,
"hi"
,
strlen
(
"hi"
))
==
0
);
ok1
(
data
.
dsize
==
expect
->
dsize
);
...
...
@@ -60,7 +60,7 @@ static int test_traverse(struct tdb1_context *tdb, TDB1_DATA key, TDB1_DATA data
int
main
(
int
argc
,
char
*
argv
[])
{
struct
tdb1_context
*
tdb
;
TDB
1
_DATA
key
,
orig_data
,
data
;
TDB_DATA
key
,
orig_data
,
data
;
uint32_t
hash
;
tdb1_off_t
rec_ptr
;
struct
tdb1_record
rec
;
...
...
@@ -81,7 +81,7 @@ int main(int argc, char *argv[])
orig_data
.
dsize
=
strlen
(
"world"
);
orig_data
.
dptr
=
(
void
*
)
"world"
;
ok1
(
tdb1_store
(
tdb
,
key
,
orig_data
,
TDB
1
_INSERT
)
==
0
);
ok1
(
tdb1_store
(
tdb
,
key
,
orig_data
,
TDB_INSERT
)
==
0
);
data
=
tdb1_fetch
(
tdb
,
key
);
ok1
(
data
.
dsize
==
strlen
(
"world"
));
...
...
@@ -105,7 +105,7 @@ int main(int argc, char *argv[])
/* Transactions should work. */
ok1
(
tdb1_transaction_start
(
tdb
)
==
0
);
ok1
(
tdb1_store
(
tdb
,
key
,
orig_data
,
TDB
1
_INSERT
)
==
0
);
ok1
(
tdb1_store
(
tdb
,
key
,
orig_data
,
TDB_INSERT
)
==
0
);
data
=
tdb1_fetch
(
tdb
,
key
);
ok1
(
data
.
dsize
==
strlen
(
"world"
));
...
...
ccan/tdb2/test/run-tdb1-check.c
View file @
8a47d50d
...
...
@@ -7,7 +7,7 @@
int
main
(
int
argc
,
char
*
argv
[])
{
struct
tdb1_context
*
tdb
;
TDB
1
_DATA
key
,
data
;
TDB_DATA
key
,
data
;
plan_tests
(
13
);
tdb
=
tdb1_open_ex
(
"run-check.tdb"
,
1
,
TDB1_CLEAR_IF_FIRST
,
...
...
@@ -21,7 +21,7 @@ int main(int argc, char *argv[])
data
.
dsize
=
strlen
(
"world"
);
data
.
dptr
=
(
void
*
)
"world"
;
ok1
(
tdb1_store
(
tdb
,
key
,
data
,
TDB
1
_INSERT
)
==
0
);
ok1
(
tdb1_store
(
tdb
,
key
,
data
,
TDB_INSERT
)
==
0
);
ok1
(
tdb1_check
(
tdb
,
NULL
,
NULL
)
==
0
);
tdb1_close
(
tdb
);
...
...
ccan/tdb2/test/run-tdb1-corrupt.c
View file @
8a47d50d
...
...
@@ -4,7 +4,7 @@
#include <err.h>
#include "tdb1-logging.h"
static
int
check
(
TDB
1_DATA
key
,
TDB1
_DATA
data
,
void
*
private
)
static
int
check
(
TDB
_DATA
key
,
TDB
_DATA
data
,
void
*
private
)
{
unsigned
int
*
sizes
=
private
;
...
...
@@ -42,7 +42,7 @@ static void tdb1_flip_bit(struct tdb1_context *tdb, unsigned int bit)
static
void
check_test
(
struct
tdb1_context
*
tdb
)
{
TDB
1
_DATA
key
,
data
;
TDB_DATA
key
,
data
;
unsigned
int
i
,
verifiable
,
corrupt
,
sizes
[
2
],
dsize
,
ksize
;
ok1
(
tdb1_check
(
tdb
,
NULL
,
NULL
)
==
0
);
...
...
@@ -58,13 +58,13 @@ static void check_test(struct tdb1_context *tdb)
for
(
key
.
dsize
=
1
;
key
.
dsize
<=
5
;
key
.
dsize
++
)
{
ksize
+=
key
.
dsize
;
dsize
+=
data
.
dsize
;
if
(
tdb1_store
(
tdb
,
key
,
data
,
TDB
1
_INSERT
)
!=
0
)
if
(
tdb1_store
(
tdb
,
key
,
data
,
TDB_INSERT
)
!=
0
)
abort
();
}
/* This is how many bytes we expect to be verifiable. */
/* From the file header. */
verifiable
=
strlen
(
TDB
1
_MAGIC_FOOD
)
+
1
verifiable
=
strlen
(
TDB_MAGIC_FOOD
)
+
1
+
2
*
sizeof
(
uint32_t
)
+
2
*
sizeof
(
tdb1_off_t
)
+
2
*
sizeof
(
uint32_t
);
/* From the free list chain and hash chains. */
...
...
ccan/tdb2/test/run-tdb1-die-during-transaction.c
View file @
8a47d50d
...
...
@@ -82,7 +82,7 @@ static int ftruncate_check(int fd, off_t length)
static
bool
test_death
(
enum
operation
op
,
struct
agent
*
agent
)
{
struct
tdb1_context
*
tdb
=
NULL
;
TDB
1
_DATA
key
;
TDB_DATA
key
;
enum
agent_return
ret
;
int
needed_recovery
=
0
;
...
...
@@ -150,7 +150,7 @@ reset:
/* Put key for agent to fetch. */
key
.
dsize
=
strlen
(
KEY_STRING
);
key
.
dptr
=
(
void
*
)
KEY_STRING
;
if
(
tdb1_store
(
tdb
,
key
,
key
,
TDB
1
_INSERT
)
!=
0
)
if
(
tdb1_store
(
tdb
,
key
,
key
,
TDB_INSERT
)
!=
0
)
return
false
;
/* This is the key we insert in transaction. */
...
...
@@ -168,7 +168,7 @@ reset:
if
(
tdb1_transaction_start
(
tdb
)
!=
0
)
return
false
;
if
(
tdb1_store
(
tdb
,
key
,
key
,
TDB
1
_INSERT
)
!=
0
)
if
(
tdb1_store
(
tdb
,
key
,
key
,
TDB_INSERT
)
!=
0
)
return
false
;
if
(
tdb1_transaction_commit
(
tdb
)
!=
0
)
...
...
ccan/tdb2/test/run-tdb1-endian.c
View file @
8a47d50d
...
...
@@ -7,7 +7,7 @@
int
main
(
int
argc
,
char
*
argv
[])
{
struct
tdb1_context
*
tdb
;
TDB
1
_DATA
key
,
data
;
TDB_DATA
key
,
data
;
plan_tests
(
13
);
tdb
=
tdb1_open_ex
(
"run-endian.tdb"
,
1024
,
...
...
@@ -20,12 +20,12 @@ int main(int argc, char *argv[])
data
.
dsize
=
strlen
(
"world"
);
data
.
dptr
=
(
void
*
)
"world"
;
ok1
(
tdb1_store
(
tdb
,
key
,
data
,
TDB
1
_MODIFY
)
<
0
);
ok1
(
tdb1_store
(
tdb
,
key
,
data
,
TDB_MODIFY
)
<
0
);
ok1
(
tdb_error
(
tdb
)
==
TDB_ERR_NOEXIST
);
ok1
(
tdb1_store
(
tdb
,
key
,
data
,
TDB
1
_INSERT
)
==
0
);
ok1
(
tdb1_store
(
tdb
,
key
,
data
,
TDB
1
_INSERT
)
<
0
);
ok1
(
tdb1_store
(
tdb
,
key
,
data
,
TDB_INSERT
)
==
0
);
ok1
(
tdb1_store
(
tdb
,
key
,
data
,
TDB_INSERT
)
<
0
);
ok1
(
tdb_error
(
tdb
)
==
TDB_ERR_EXISTS
);
ok1
(
tdb1_store
(
tdb
,
key
,
data
,
TDB
1
_MODIFY
)
==
0
);
ok1
(
tdb1_store
(
tdb
,
key
,
data
,
TDB_MODIFY
)
==
0
);
data
=
tdb1_fetch
(
tdb
,
key
);
ok1
(
data
.
dsize
==
strlen
(
"world"
));
...
...
ccan/tdb2/test/run-tdb1-incompatible.c
View file @
8a47d50d
...
...
@@ -3,7 +3,7 @@
#include <stdlib.h>
#include <err.h>
static
unsigned
int
tdb1_dumb_hash
(
TDB
1
_DATA
*
key
)
static
unsigned
int
tdb1_dumb_hash
(
TDB_DATA
*
key
)
{
return
key
->
dsize
;
}
...
...
@@ -35,7 +35,7 @@ int main(int argc, char *argv[])
{
struct
tdb1_context
*
tdb
;
unsigned
int
log_count
,
flags
;
TDB
1
_DATA
d
;
TDB_DATA
d
;
struct
tdb1_logging_context
log_ctx
=
{
log_fn
,
&
log_count
};
plan_tests
(
38
*
2
);
...
...
@@ -55,7 +55,7 @@ int main(int argc, char *argv[])
ok1
(
log_count
==
0
);
d
.
dptr
=
(
void
*
)
"Hello"
;
d
.
dsize
=
5
;
ok1
(
tdb1_store
(
tdb
,
d
,
d
,
TDB
1
_INSERT
)
==
0
);
ok1
(
tdb1_store
(
tdb
,
d
,
d
,
TDB_INSERT
)
==
0
);
tdb1_close
(
tdb
);
/* Should not have marked rwlocks field. */
...
...
@@ -100,7 +100,7 @@ int main(int argc, char *argv[])
ok1
(
log_count
==
0
);
d
.
dptr
=
(
void
*
)
"Hello"
;
d
.
dsize
=
5
;
ok1
(
tdb1_store
(
tdb
,
d
,
d
,
TDB
1
_INSERT
)
==
0
);
ok1
(
tdb1_store
(
tdb
,
d
,
d
,
TDB_INSERT
)
==
0
);
tdb1_close
(
tdb
);
/* Should have marked rwlocks field. */
...
...
@@ -149,7 +149,7 @@ int main(int argc, char *argv[])
ok1
(
log_count
==
0
);
d
.
dptr
=
(
void
*
)
"Hello"
;
d
.
dsize
=
5
;
ok1
(
tdb1_store
(
tdb
,
d
,
d
,
TDB
1
_INSERT
)
==
0
);
ok1
(
tdb1_store
(
tdb
,
d
,
d
,
TDB_INSERT
)
==
0
);
tdb1_close
(
tdb
);
/* Should have marked rwlocks field. */
...
...
ccan/tdb2/test/run-tdb1-nested-transactions.c
View file @
8a47d50d
...
...
@@ -8,7 +8,7 @@
int
main
(
int
argc
,
char
*
argv
[])
{
struct
tdb1_context
*
tdb
;
TDB
1
_DATA
key
,
data
;
TDB_DATA
key
,
data
;
plan_tests
(
27
);
key
.
dsize
=
strlen
(
"hi"
);
...
...
@@ -22,7 +22,7 @@ int main(int argc, char *argv[])
ok1
(
tdb1_transaction_start
(
tdb
)
==
0
);
data
.
dptr
=
(
void
*
)
"world"
;
data
.
dsize
=
strlen
(
"world"
);
ok1
(
tdb1_store
(
tdb
,
key
,
data
,
TDB
1
_INSERT
)
==
0
);
ok1
(
tdb1_store
(
tdb
,
key
,
data
,
TDB_INSERT
)
==
0
);
data
=
tdb1_fetch
(
tdb
,
key
);
ok1
(
data
.
dsize
==
strlen
(
"world"
));
ok1
(
memcmp
(
data
.
dptr
,
"world"
,
strlen
(
"world"
))
==
0
);
...
...
ccan/tdb2/test/run-tdb1-nested-traverse.c
View file @
8a47d50d
...
...
@@ -11,19 +11,19 @@
static
struct
agent
*
agent
;
static
bool
correct_key
(
TDB
1
_DATA
key
)
static
bool
correct_key
(
TDB_DATA
key
)
{
return
key
.
dsize
==
strlen
(
"hi"
)
&&
memcmp
(
key
.
dptr
,
"hi"
,
key
.
dsize
)
==
0
;
}
static
bool
correct_data
(
TDB
1
_DATA
data
)
static
bool
correct_data
(
TDB_DATA
data
)
{
return
data
.
dsize
==
strlen
(
"world"
)
&&
memcmp
(
data
.
dptr
,
"world"
,
data
.
dsize
)
==
0
;
}
static
int
traverse2
(
struct
tdb1_context
*
tdb
,
TDB
1_DATA
key
,
TDB1
_DATA
data
,
static
int
traverse2
(
struct
tdb1_context
*
tdb
,
TDB
_DATA
key
,
TDB
_DATA
data
,
void
*
p
)
{
ok1
(
correct_key
(
key
));
...
...
@@ -31,7 +31,7 @@ static int traverse2(struct tdb1_context *tdb, TDB1_DATA key, TDB1_DATA data,
return
0
;
}
static
int
traverse1
(
struct
tdb1_context
*
tdb
,
TDB
1_DATA
key
,
TDB1
_DATA
data
,
static
int
traverse1
(
struct
tdb1_context
*
tdb
,
TDB
_DATA
key
,
TDB
_DATA
data
,
void
*
p
)
{
ok1
(
correct_key
(
key
));
...
...
@@ -49,7 +49,7 @@ static int traverse1(struct tdb1_context *tdb, TDB1_DATA key, TDB1_DATA data,
int
main
(
int
argc
,
char
*
argv
[])
{
struct
tdb1_context
*
tdb
;
TDB
1
_DATA
key
,
data
;
TDB_DATA
key
,
data
;
plan_tests
(
17
);
agent
=
prepare_external_agent1
();
...
...
@@ -71,7 +71,7 @@ int main(int argc, char *argv[])
data
.
dptr
=
(
void
*
)
"world"
;
data
.
dsize
=
strlen
(
"world"
);
ok1
(
tdb1_store
(
tdb
,
key
,
data
,
TDB
1
_INSERT
)
==
0
);
ok1
(
tdb1_store
(
tdb
,
key
,
data
,
TDB_INSERT
)
==
0
);
tdb1_traverse
(
tdb
,
traverse1
,
NULL
);
tdb1_traverse_read
(
tdb
,
traverse1
,
NULL
);
tdb1_close
(
tdb
);
...
...
ccan/tdb2/test/run-tdb1-no-lock-during-traverse.c
View file @
8a47d50d
...
...
@@ -17,7 +17,7 @@
static
bool
prepare_entries
(
struct
tdb1_context
*
tdb
)
{
unsigned
int
i
;
TDB
1
_DATA
key
,
data
;
TDB_DATA
key
,
data
;
for
(
i
=
0
;
i
<
NUM_ENTRIES
;
i
++
)
{
key
.
dsize
=
sizeof
(
i
);
...
...
@@ -34,7 +34,7 @@ static bool prepare_entries(struct tdb1_context *tdb)
static
void
delete_entries
(
struct
tdb1_context
*
tdb
)
{
unsigned
int
i
;
TDB
1
_DATA
key
;
TDB_DATA
key
;
for
(
i
=
0
;
i
<
NUM_ENTRIES
;
i
++
)
{
key
.
dsize
=
sizeof
(
i
);
...
...
@@ -45,7 +45,7 @@ static void delete_entries(struct tdb1_context *tdb)
}
/* We don't know how many times this will run. */
static
int
delete_other
(
struct
tdb1_context
*
tdb
,
TDB
1_DATA
key
,
TDB1
_DATA
data
,
static
int
delete_other
(
struct
tdb1_context
*
tdb
,
TDB
_DATA
key
,
TDB
_DATA
data
,
void
*
private_data
)
{
unsigned
int
i
;
...
...
@@ -57,7 +57,7 @@ static int delete_other(struct tdb1_context *tdb, TDB1_DATA key, TDB1_DATA data,
return
0
;
}
static
int
delete_self
(
struct
tdb1_context
*
tdb
,
TDB
1_DATA
key
,
TDB1
_DATA
data
,
static
int
delete_self
(
struct
tdb1_context
*
tdb
,
TDB
_DATA
key
,
TDB
_DATA
data
,
void
*
private_data
)
{
ok1
(
tdb1_delete
(
tdb
,
key
)
==
0
);
...
...
ccan/tdb2/test/run-tdb1-open-during-transaction.c
View file @
8a47d50d
...
...
@@ -138,7 +138,7 @@ int main(int argc, char *argv[])
TDB1_CLEAR_IF_FIRST
|
TDB1_NOMMAP
};
int
i
;
struct
tdb1_context
*
tdb
;
TDB
1
_DATA
key
,
data
;
TDB_DATA
key
,
data
;
plan_tests
(
20
);
agent
=
prepare_external_agent1
();
...
...
@@ -164,7 +164,7 @@ int main(int argc, char *argv[])
data
.
dptr
=
(
void
*
)
"world"
;
data
.
dsize
=
strlen
(
"world"
);
ok1
(
tdb1_store
(
tdb
,
key
,
data
,
TDB
1
_INSERT
)
==
0
);
ok1
(
tdb1_store
(
tdb
,
key
,
data
,
TDB_INSERT
)
==
0
);
ok1
(
tdb1_transaction_commit
(
tdb
)
==
0
);
ok
(
!
errors
,
"We had %u open errors"
,
errors
);
...
...
ccan/tdb2/test/run-tdb1-readonly-check.c
View file @
8a47d50d
...
...
@@ -9,7 +9,7 @@
int
main
(
int
argc
,
char
*
argv
[])
{
struct
tdb1_context
*
tdb
;
TDB
1
_DATA
key
,
data
;
TDB_DATA
key
,
data
;
plan_tests
(
11
);
tdb
=
tdb1_open_ex
(
"run-readonly-check.tdb"
,
1024
,
...
...
@@ -22,7 +22,7 @@ int main(int argc, char *argv[])
data
.
dsize
=
strlen
(
"world"
);
data
.
dptr
=
(
void
*
)
"world"
;
ok1
(
tdb1_store
(
tdb
,
key
,
data
,
TDB
1
_INSERT
)
==
0
);
ok1
(
tdb1_store
(
tdb
,
key
,
data
,
TDB_INSERT
)
==
0
);
ok1
(
tdb1_check
(
tdb
,
NULL
,
NULL
)
==
0
);
/* We are also allowed to do a check inside a transaction. */
...
...
@@ -34,7 +34,7 @@ int main(int argc, char *argv[])
TDB1_DEFAULT
,
O_RDONLY
,
0
,
&
taplogctx
,
NULL
);
ok1
(
tdb
);
ok1
(
tdb1_store
(
tdb
,
key
,
data
,
TDB
1
_MODIFY
)
==
-
1
);
ok1
(
tdb1_store
(
tdb
,
key
,
data
,
TDB_MODIFY
)
==
-
1
);
ok1
(
tdb_error
(
tdb
)
==
TDB_ERR_RDONLY
);
ok1
(
tdb1_check
(
tdb
,
NULL
,
NULL
)
==
0
);
ok1
(
tdb1_close
(
tdb
)
==
0
);
...
...
ccan/tdb2/test/run-tdb1-summary.c
View file @
8a47d50d
...
...
@@ -10,8 +10,8 @@ int main(int argc, char *argv[])
int
flags
[]
=
{
TDB1_INTERNAL
,
TDB1_DEFAULT
,
TDB1_NOMMAP
,
TDB1_INTERNAL
|
TDB1_CONVERT
,
TDB1_CONVERT
,
TDB1_NOMMAP
|
TDB1_CONVERT
};
TDB
1
_DATA
key
=
{
(
unsigned
char
*
)
&
j
,
sizeof
(
j
)
};
TDB
1
_DATA
data
=
{
(
unsigned
char
*
)
&
j
,
sizeof
(
j
)
};
TDB_DATA
key
=
{
(
unsigned
char
*
)
&
j
,
sizeof
(
j
)
};
TDB_DATA
data
=
{
(
unsigned
char
*
)
&
j
,
sizeof
(
j
)
};
char
*
summary
;
plan_tests
(
sizeof
(
flags
)
/
sizeof
(
flags
[
0
])
*
14
);
...
...
@@ -26,7 +26,7 @@ int main(int argc, char *argv[])
for
(
j
=
0
;
j
<
500
;
j
++
)
{
/* Make sure padding varies to we get some graphs! */
data
.
dsize
=
j
%
(
sizeof
(
j
)
+
1
);
if
(
tdb1_store
(
tdb
,
key
,
data
,
TDB
1
_REPLACE
)
!=
0
)
if
(
tdb1_store
(
tdb
,
key
,
data
,
TDB_REPLACE
)
!=
0
)
fail
(
"Storing in tdb"
);
}
...
...
ccan/tdb2/test/run-tdb1-traverse-in-transaction.c
View file @
8a47d50d
...
...
@@ -12,19 +12,19 @@
static
struct
agent
*
agent
;
static
bool
correct_key
(
TDB
1
_DATA
key
)
static
bool
correct_key
(
TDB_DATA
key
)
{
return
key
.
dsize
==
strlen
(
"hi"
)
&&
memcmp
(
key
.
dptr
,
"hi"
,
key
.
dsize
)
==
0
;
}
static
bool
correct_data
(
TDB
1
_DATA
data
)
static
bool
correct_data
(
TDB_DATA
data
)
{
return
data
.
dsize
==
strlen
(
"world"
)
&&
memcmp
(
data
.
dptr
,
"world"
,
data
.
dsize
)
==
0
;
}
static
int
traverse
(
struct
tdb1_context
*
tdb
,
TDB
1_DATA
key
,
TDB1
_DATA
data
,
static
int
traverse
(
struct
tdb1_context
*
tdb
,
TDB
_DATA
key
,
TDB
_DATA
data
,
void
*
p
)
{
ok1
(
correct_key
(
key
));
...
...
@@ -35,7 +35,7 @@ static int traverse(struct tdb1_context *tdb, TDB1_DATA key, TDB1_DATA data,
int
main
(
int
argc
,
char
*
argv
[])
{
struct
tdb1_context
*
tdb
;
TDB
1
_DATA
key
,
data
;
TDB_DATA
key
,
data
;
plan_tests
(
13
);
agent
=
prepare_external_agent1
();
...
...
@@ -52,7 +52,7 @@ int main(int argc, char *argv[])
data
.
dptr
=
(
void
*
)
"world"
;
data
.
dsize
=
strlen
(
"world"
);
ok1
(
tdb1_store
(
tdb
,
key
,
data
,
TDB
1
_INSERT
)
==
0
);
ok1
(
tdb1_store
(
tdb
,
key
,
data
,
TDB_INSERT
)
==
0
);
ok1
(
external_agent_operation1
(
agent
,
OPEN
,
tdb
->
name
)
==
SUCCESS
);
...
...
ccan/tdb2/test/run-tdb1-wronghash-fail.c
View file @
8a47d50d
...
...
@@ -15,7 +15,7 @@ int main(int argc, char *argv[])
{
struct
tdb1_context
*
tdb
;
unsigned
int
log_count
;
TDB
1
_DATA
d
;
TDB_DATA
d
;
struct
tdb1_logging_context
log_ctx
=
{
log_fn
,
&
log_count
};
plan_tests
(
28
);
...
...
@@ -28,7 +28,7 @@ int main(int argc, char *argv[])
ok1
(
log_count
==
0
);
d
.
dptr
=
(
void
*
)
"Hello"
;
d
.
dsize
=
5
;
ok1
(
tdb1_store
(
tdb
,
d
,
d
,
TDB
1
_INSERT
)
==
0
);
ok1
(
tdb1_store
(
tdb
,
d
,
d
,
TDB_INSERT
)
==
0
);
tdb1_close
(
tdb
);
/* Fail to open with different hash. */
...
...
ccan/tdb2/test/run-tdb1-zero-append.c
View file @
8a47d50d
...
...
@@ -7,7 +7,7 @@
int
main
(
int
argc
,
char
*
argv
[])
{
struct
tdb1_context
*
tdb
;
TDB
1
_DATA
key
,
data
;
TDB_DATA
key
,
data
;
plan_tests
(
4
);
tdb
=
tdb1_open_ex
(
NULL
,
1024
,
TDB1_INTERNAL
,
O_CREAT
|
O_TRUNC
|
O_RDWR
,
...
...
ccan/tdb2/test/run-tdb1.c
View file @
8a47d50d
...
...
@@ -7,7 +7,7 @@
int
main
(
int
argc
,
char
*
argv
[])
{
struct
tdb1_context
*
tdb
;
TDB
1
_DATA
key
,
data
;
TDB_DATA
key
,
data
;
plan_tests
(
10
);
tdb
=
tdb1_open_ex
(
"run.tdb"
,
1024
,
TDB1_CLEAR_IF_FIRST
,
...
...
@@ -19,12 +19,12 @@ int main(int argc, char *argv[])
data
.
dsize
=
strlen
(
"world"
);
data
.
dptr
=
(
void
*
)
"world"
;
ok1
(
tdb1_store
(
tdb
,
key
,
data
,
TDB
1
_MODIFY
)
<
0
);
ok1
(
tdb1_store
(
tdb
,
key
,
data
,
TDB_MODIFY
)
<
0
);
ok1
(
tdb_error
(
tdb
)
==
TDB_ERR_NOEXIST
);
ok1
(
tdb1_store
(
tdb
,
key
,
data
,
TDB
1
_INSERT
)
==
0
);
ok1
(
tdb1_store
(
tdb
,
key
,
data
,
TDB
1
_INSERT
)
<
0
);
ok1
(
tdb1_store
(
tdb
,
key
,
data
,
TDB_INSERT
)
==
0
);
ok1
(
tdb1_store
(
tdb
,
key
,
data
,
TDB_INSERT
)
<
0
);
ok1
(
tdb_error
(
tdb
)
==
TDB_ERR_EXISTS
);
ok1
(
tdb1_store
(
tdb
,
key
,
data
,
TDB
1
_MODIFY
)
==
0
);
ok1
(
tdb1_store
(
tdb
,
key
,
data
,
TDB_MODIFY
)
==
0
);
data
=
tdb1_fetch
(
tdb
,
key
);
ok1
(
data
.
dsize
==
strlen
(
"world"
));
...
...
ccan/tdb2/test/tdb1-external-agent.c
View file @
8a47d50d
...
...
@@ -20,9 +20,9 @@ static struct tdb1_context *tdb;
static
enum
agent_return
do_operation
(
enum
operation
op
,
const
char
*
name
)
{
TDB
1
_DATA
k
;
TDB_DATA
k
;
enum
agent_return
ret
;
TDB
1
_DATA
data
;
TDB_DATA
data
;
if
(
op
!=
OPEN
&&
op
!=
OPEN_WITH_CLEAR_IF_FIRST
&&
!
tdb
)
{
diag
(
"external: No tdb open!"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment