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
2cad8789
Commit
2cad8789
authored
Jun 29, 2009
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix traverse nesting unlock bug.
parent
e84f843d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
83 additions
and
7 deletions
+83
-7
ccan/tdb/test/run-nested-traverse.c
ccan/tdb/test/run-nested-traverse.c
+71
-0
ccan/tdb/traverse.c
ccan/tdb/traverse.c
+12
-7
No files found.
ccan/tdb/test/run-nested-traverse.c
0 → 100644
View file @
2cad8789
#define _XOPEN_SOURCE 500
#include "tdb/tdb.h"
#include "tdb/io.c"
#include "tdb/tdb.c"
#include "tdb/lock.c"
#include "tdb/freelist.c"
#include "tdb/traverse.c"
#include "tdb/transaction.c"
#include "tdb/error.c"
#include "tdb/open.c"
#include "tap/tap.h"
#include <stdlib.h>
#include <stdbool.h>
#include <err.h>
static
bool
correct_key
(
TDB_DATA
key
)
{
return
key
.
dsize
==
strlen
(
"hi"
)
&&
memcmp
(
key
.
dptr
,
"hi"
,
key
.
dsize
)
==
0
;
}
static
bool
correct_data
(
TDB_DATA
data
)
{
return
data
.
dsize
==
strlen
(
"world"
)
&&
memcmp
(
data
.
dptr
,
"world"
,
data
.
dsize
)
==
0
;
}
static
int
traverse2
(
struct
tdb_context
*
tdb
,
TDB_DATA
key
,
TDB_DATA
data
,
void
*
p
)
{
ok1
(
correct_key
(
key
));
ok1
(
correct_data
(
data
));
return
0
;
}
static
int
traverse1
(
struct
tdb_context
*
tdb
,
TDB_DATA
key
,
TDB_DATA
data
,
void
*
p
)
{
ok1
(
correct_key
(
key
));
ok1
(
correct_data
(
data
));
ok1
(
tdb
->
have_transaction_lock
);
tdb_traverse
(
tdb
,
traverse2
,
NULL
);
/* That should *not* release the transaction lock! */
ok1
(
tdb
->
have_transaction_lock
);
return
0
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
struct
tdb_context
*
tdb
;
TDB_DATA
key
,
data
;
plan_tests
(
14
);
tdb
=
tdb_open
(
"/tmp/test.tdb"
,
1024
,
TDB_CLEAR_IF_FIRST
,
O_CREAT
|
O_TRUNC
|
O_RDWR
,
0600
);
ok1
(
tdb
);
/* Tickle bug on appending zero length buffer to zero length buffer. */
key
.
dsize
=
strlen
(
"hi"
);
key
.
dptr
=
(
void
*
)
"hi"
;
data
.
dptr
=
(
void
*
)
"world"
;
data
.
dsize
=
strlen
(
"world"
);
ok1
(
tdb_store
(
tdb
,
key
,
data
,
TDB_INSERT
)
==
0
);
tdb_traverse
(
tdb
,
traverse1
,
NULL
);
tdb_traverse_read
(
tdb
,
traverse1
,
NULL
);
tdb_close
(
tdb
);
return
exit_status
();
}
ccan/tdb/traverse.c
View file @
2cad8789
...
...
@@ -182,6 +182,7 @@ static int tdb_traverse_internal(struct tdb_context *tdb,
}
if
(
fn
&&
fn
(
tdb
,
key
,
dbuf
,
private_data
))
{
/* They want us to terminate traversal */
tdb_trace
(
tdb
,
"tdb_traverse_end = %i
\n
"
,
count
);
ret
=
count
;
if
(
tdb_unlock_record
(
tdb
,
tl
->
off
)
!=
0
)
{
TDB_LOG
((
tdb
,
TDB_DEBUG_FATAL
,
"tdb_traverse: unlock_record failed!
\n
"
));;
...
...
@@ -192,6 +193,7 @@ static int tdb_traverse_internal(struct tdb_context *tdb,
}
SAFE_FREE
(
key
.
dptr
);
}
tdb_trace
(
tdb
,
"tdb_traverse_end
\n
"
);
out:
tdb
->
travlocks
.
next
=
tl
->
next
;
if
(
ret
<
0
)
...
...
@@ -212,17 +214,18 @@ int tdb_traverse_read(struct tdb_context *tdb,
/* we need to get a read lock on the transaction lock here to
cope with the lock ordering semantics of solaris10 */
if
(
tdb_transaction_lock
(
tdb
,
F_RDLCK
))
{
if
(
tdb
->
traverse_read
==
0
&&
tdb
_transaction_lock
(
tdb
,
F_RDLCK
))
{
return
-
1
;
}
tdb
->
traverse_read
++
;
tdb_trace
(
tdb
,
"tdb_traverse_read_start
\n
"
);
ret
=
tdb_traverse_internal
(
tdb
,
fn
,
private_data
,
&
tl
);
tdb_trace
(
tdb
,
"tdb_traverse_end = %i
\n
"
,
ret
);
tdb
->
traverse_read
--
;
tdb_transaction_unlock
(
tdb
);
if
(
tdb
->
traverse_read
==
0
)
{
tdb_transaction_unlock
(
tdb
);
}
return
ret
;
}
...
...
@@ -243,18 +246,20 @@ int tdb_traverse(struct tdb_context *tdb,
if
(
tdb
->
read_only
||
tdb
->
traverse_read
)
{
return
tdb_traverse_read
(
tdb
,
fn
,
private_data
);
}
if
(
tdb_transaction_lock
(
tdb
,
F_WRLCK
))
{
/* Nested traversals: transaction lock doesn't nest. */
if
(
tdb
->
traverse_write
==
0
&&
tdb_transaction_lock
(
tdb
,
F_WRLCK
))
{
return
-
1
;
}
tdb
->
traverse_write
++
;
tdb_trace
(
tdb
,
"tdb_traverse_start
\n
"
);
ret
=
tdb_traverse_internal
(
tdb
,
fn
,
private_data
,
&
tl
);
tdb_trace
(
tdb
,
"tdb_traverse_end = %i
\n
"
,
ret
);
tdb
->
traverse_write
--
;
tdb_transaction_unlock
(
tdb
);
if
(
tdb
->
traverse_write
==
0
)
{
tdb_transaction_unlock
(
tdb
);
}
return
ret
;
}
...
...
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