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
3352e4e9
Commit
3352e4e9
authored
Aug 31, 2011
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tdb2: unify tdb1_parse_record into tdb_parse_record
Switch on the TDB_VERSION1 flag.
parent
ceb2f3ea
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
32 additions
and
44 deletions
+32
-44
ccan/tdb2/private.h
ccan/tdb2/private.h
+5
-0
ccan/tdb2/tdb.c
ccan/tdb2/tdb.c
+5
-0
ccan/tdb2/tdb1.h
ccan/tdb2/tdb1.h
+0
-5
ccan/tdb2/tdb1_io.c
ccan/tdb2/tdb1_io.c
+9
-9
ccan/tdb2/tdb1_private.h
ccan/tdb2/tdb1_private.h
+6
-5
ccan/tdb2/tdb1_tdb.c
ccan/tdb2/tdb1_tdb.c
+7
-25
No files found.
ccan/tdb2/private.h
View file @
3352e4e9
...
...
@@ -665,6 +665,11 @@ enum TDB_ERROR tdb1_fetch(struct tdb_context *tdb, TDB_DATA key,
int
tdb1_append
(
struct
tdb_context
*
tdb
,
TDB_DATA
key
,
TDB_DATA
new_dbuf
);
int
tdb1_delete
(
struct
tdb_context
*
tdb
,
TDB_DATA
key
);
int
tdb1_exists
(
struct
tdb_context
*
tdb
,
TDB_DATA
key
);
enum
TDB_ERROR
tdb1_parse_record
(
struct
tdb_context
*
tdb
,
TDB_DATA
key
,
enum
TDB_ERROR
(
*
parser
)(
TDB_DATA
key
,
TDB_DATA
data
,
void
*
private_data
),
void
*
private_data
);
/* tdb.c: */
enum
TDB_ERROR
COLD
tdb_logerr
(
struct
tdb_context
*
tdb
,
...
...
ccan/tdb2/tdb.c
View file @
3352e4e9
...
...
@@ -526,6 +526,11 @@ enum TDB_ERROR tdb_parse_record_(struct tdb_context *tdb,
struct
hash_info
h
;
enum
TDB_ERROR
ecode
;
if
(
tdb
->
flags
&
TDB_VERSION1
)
{
return
tdb
->
last_error
=
tdb1_parse_record
(
tdb
,
key
,
parse
,
data
);
}
off
=
find_and_lock
(
tdb
,
key
,
F_RDLCK
,
&
h
,
&
rec
,
NULL
);
if
(
TDB_OFF_IS_ERR
(
off
))
{
return
tdb
->
last_error
=
off
;
...
...
ccan/tdb2/tdb1.h
View file @
3352e4e9
...
...
@@ -38,11 +38,6 @@
void
tdb1_set_max_dead
(
struct
tdb_context
*
tdb
,
int
max_dead
);
int
tdb1_parse_record
(
struct
tdb_context
*
tdb
,
TDB_DATA
key
,
int
(
*
parser
)(
TDB_DATA
key
,
TDB_DATA
data
,
void
*
private_data
),
void
*
private_data
);
TDB_DATA
tdb1_firstkey
(
struct
tdb_context
*
tdb
);
TDB_DATA
tdb1_nextkey
(
struct
tdb_context
*
tdb
,
TDB_DATA
key
);
...
...
ccan/tdb2/tdb1_io.c
View file @
3352e4e9
...
...
@@ -435,15 +435,15 @@ unsigned char *tdb1_alloc_read(struct tdb_context *tdb, tdb1_off_t offset, tdb1_
}
/* Give a piece of tdb data to a parser */
int
tdb1_parse_data
(
struct
tdb_context
*
tdb
,
TDB_DATA
key
,
tdb1_off_t
offset
,
tdb1_len_t
len
,
int
(
*
parser
)(
TDB_DATA
key
,
TDB_DATA
data
,
void
*
private_data
),
void
*
private_data
)
enum
TDB_ERROR
tdb1_parse_data
(
struct
tdb_context
*
tdb
,
TDB_DATA
key
,
tdb1_off_t
offset
,
tdb1_len_t
len
,
enum
TDB_ERROR
(
*
parser
)(
TDB_DATA
key
,
TDB_DATA
data
,
void
*
private_data
),
void
*
private_data
)
{
TDB_DATA
data
;
int
result
;
enum
TDB_ERROR
result
;
data
.
dsize
=
len
;
...
...
@@ -453,14 +453,14 @@ int tdb1_parse_data(struct tdb_context *tdb, TDB_DATA key,
* parser directly at the mmap area.
*/
if
(
tdb
->
tdb1
.
io
->
tdb1_oob
(
tdb
,
offset
+
len
,
0
)
!=
0
)
{
return
-
1
;
return
tdb
->
last_error
;
}
data
.
dptr
=
offset
+
(
unsigned
char
*
)
tdb
->
file
->
map_ptr
;
return
parser
(
key
,
data
,
private_data
);
}
if
(
!
(
data
.
dptr
=
tdb1_alloc_read
(
tdb
,
offset
,
len
)))
{
return
-
1
;
return
tdb
->
last_error
;
}
result
=
parser
(
key
,
data
,
private_data
);
...
...
ccan/tdb2/tdb1_private.h
View file @
3352e4e9
...
...
@@ -159,11 +159,12 @@ int tdb1_rec_read(struct tdb_context *tdb, tdb1_off_t offset, struct tdb1_record
int
tdb1_rec_write
(
struct
tdb_context
*
tdb
,
tdb1_off_t
offset
,
struct
tdb1_record
*
rec
);
int
tdb1_do_delete
(
struct
tdb_context
*
tdb
,
tdb1_off_t
rec_ptr
,
struct
tdb1_record
*
rec
);
unsigned
char
*
tdb1_alloc_read
(
struct
tdb_context
*
tdb
,
tdb1_off_t
offset
,
tdb1_len_t
len
);
int
tdb1_parse_data
(
struct
tdb_context
*
tdb
,
TDB_DATA
key
,
tdb1_off_t
offset
,
tdb1_len_t
len
,
int
(
*
parser
)(
TDB_DATA
key
,
TDB_DATA
data
,
void
*
private_data
),
void
*
private_data
);
enum
TDB_ERROR
tdb1_parse_data
(
struct
tdb_context
*
tdb
,
TDB_DATA
key
,
tdb1_off_t
offset
,
tdb1_len_t
len
,
enum
TDB_ERROR
(
*
parser
)(
TDB_DATA
key
,
TDB_DATA
data
,
void
*
private_data
),
void
*
private_data
);
tdb1_off_t
tdb1_find_lock_hash
(
struct
tdb_context
*
tdb
,
TDB_DATA
key
,
uint32_t
hash
,
int
locktype
,
struct
tdb1_record
*
rec
);
void
tdb1_io_init
(
struct
tdb_context
*
tdb
);
...
...
ccan/tdb2/tdb1_tdb.c
View file @
3352e4e9
...
...
@@ -209,32 +209,15 @@ enum TDB_ERROR tdb1_fetch(struct tdb_context *tdb, TDB_DATA key, TDB_DATA *data)
return
TDB_SUCCESS
;
}
/*
* Find an entry in the database and hand the record's data to a parsing
* function. The parsing function is executed under the chain read lock, so it
* should be fast and should not block on other syscalls.
*
* DON'T CALL OTHER TDB CALLS FROM THE PARSER, THIS MIGHT LEAD TO SEGFAULTS.
*
* For mmapped tdb's that do not have a transaction open it points the parsing
* function directly at the mmap area, it avoids the malloc/memcpy in this
* case. If a transaction is open or no mmap is available, it has to do
* malloc/read/parse/free.
*
* This is interesting for all readers of potentially large data structures in
* the tdb records, ldb indexes being one example.
*
* Return -1 if the record was not found.
*/
int
tdb1_parse_record
(
struct
tdb_context
*
tdb
,
TDB_DATA
key
,
int
(
*
parser
)(
TDB_DATA
key
,
TDB_DATA
data
,
void
*
private_data
),
void
*
private_data
)
enum
TDB_ERROR
tdb1_parse_record
(
struct
tdb_context
*
tdb
,
TDB_DATA
key
,
enum
TDB_ERROR
(
*
parser
)(
TDB_DATA
key
,
TDB_DATA
data
,
void
*
private_data
),
void
*
private_data
)
{
tdb1_off_t
rec_ptr
;
struct
tdb1_record
rec
;
int
ret
;
enum
TDB_ERROR
ret
;
uint32_t
hash
;
/* find which hash bucket it is in */
...
...
@@ -242,8 +225,7 @@ int tdb1_parse_record(struct tdb_context *tdb, TDB_DATA key,
if
(
!
(
rec_ptr
=
tdb1_find_lock_hash
(
tdb
,
key
,
hash
,
F_RDLCK
,
&
rec
)))
{
/* record not found */
tdb
->
last_error
=
TDB_ERR_NOEXIST
;
return
-
1
;
return
TDB_ERR_NOEXIST
;
}
ret
=
tdb1_parse_data
(
tdb
,
key
,
rec_ptr
+
sizeof
(
rec
)
+
rec
.
key_len
,
...
...
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