1 #include "../common/tdb_private.h"
2 #include "lock-tracking.h"
4 #define fcntl fcntl_with_lockcheck
6 #include "../common/io.c"
7 #include "../common/tdb.c"
8 #include "../common/lock.c"
9 #include "../common/freelist.c"
10 #include "../common/traverse.c"
11 #include "../common/transaction.c"
12 #include "../common/error.c"
13 #include "../common/open.c"
14 #include "../common/check.c"
15 #include "../common/hash.c"
16 #include "../common/mutex.c"
17 #include "tap-interface.h"
23 #define NUM_ENTRIES 10
25 static bool prepare_entries(struct tdb_context
*tdb
)
30 for (i
= 0; i
< NUM_ENTRIES
; i
++) {
31 key
.dsize
= sizeof(i
);
32 key
.dptr
= (void *)&i
;
33 data
.dsize
= strlen("world");
34 data
.dptr
= discard_const_p(uint8_t, "world");
36 if (tdb_store(tdb
, key
, data
, 0) != 0)
42 static void delete_entries(struct tdb_context
*tdb
)
47 for (i
= 0; i
< NUM_ENTRIES
; i
++) {
48 key
.dsize
= sizeof(i
);
49 key
.dptr
= (void *)&i
;
51 ok1(tdb_delete(tdb
, key
) == 0);
55 /* We don't know how many times this will run. */
56 static int delete_other(struct tdb_context
*tdb
, TDB_DATA key
, TDB_DATA data
,
60 memcpy(&i
, key
.dptr
, 4);
61 i
= (i
+ 1) % NUM_ENTRIES
;
62 key
.dptr
= (void *)&i
;
63 if (tdb_delete(tdb
, key
) != 0)
64 (*(int *)private_data
)++;
68 static int delete_self(struct tdb_context
*tdb
, TDB_DATA key
, TDB_DATA data
,
71 ok1(tdb_delete(tdb
, key
) == 0);
75 int main(int argc
, char *argv
[])
77 struct tdb_context
*tdb
;
81 tdb
= tdb_open_ex("run-no-lock-during-traverse.tdb",
82 1024, TDB_CLEAR_IF_FIRST
, O_CREAT
|O_TRUNC
|O_RDWR
,
83 0600, &taplogctx
, NULL
);
86 ok1(prepare_entries(tdb
));
87 ok1(locking_errors
== 0);
88 ok1(tdb_lockall(tdb
) == 0);
89 ok1(locking_errors
== 0);
90 tdb_traverse(tdb
, delete_other
, &errors
);
92 ok1(locking_errors
== 0);
93 ok1(tdb_unlockall(tdb
) == 0);
95 ok1(prepare_entries(tdb
));
96 ok1(locking_errors
== 0);
97 ok1(tdb_lockall(tdb
) == 0);
98 ok1(locking_errors
== 0);
99 tdb_traverse(tdb
, delete_self
, NULL
);
100 ok1(locking_errors
== 0);
101 ok1(tdb_unlockall(tdb
) == 0);
103 ok1(prepare_entries(tdb
));
104 ok1(locking_errors
== 0);
105 ok1(tdb_lockall(tdb
) == 0);
106 ok1(locking_errors
== 0);
108 ok1(locking_errors
== 0);
109 ok1(tdb_unlockall(tdb
) == 0);
111 ok1(tdb_close(tdb
) == 0);
113 return exit_status();