3 #include "tdb1-lock-tracking.h"
5 #define fcntl fcntl_with_lockcheck1
7 #include "tdb2-source.h"
8 #include "tap-interface.h"
15 #define NUM_ENTRIES 10
17 static bool prepare_entries(struct tdb_context
*tdb
)
22 for (i
= 0; i
< NUM_ENTRIES
; i
++) {
23 key
.dsize
= sizeof(i
);
24 key
.dptr
= (void *)&i
;
25 data
= tdb_mkdata("world", strlen("world"));
27 if (tdb_store(tdb
, key
, data
, 0) != TDB_SUCCESS
)
33 static void delete_entries(struct tdb_context
*tdb
)
38 for (i
= 0; i
< NUM_ENTRIES
; i
++) {
39 key
.dsize
= sizeof(i
);
40 key
.dptr
= (void *)&i
;
42 ok1(tdb_delete(tdb
, key
) == TDB_SUCCESS
);
46 /* We don't know how many times this will run. */
47 static int delete_other(struct tdb_context
*tdb
, TDB_DATA key
, TDB_DATA data
,
51 memcpy(&i
, key
.dptr
, 4);
52 i
= (i
+ 1) % NUM_ENTRIES
;
53 key
.dptr
= (void *)&i
;
54 if (tdb_delete(tdb
, key
) != TDB_SUCCESS
)
55 (*(int *)private_data
)++;
59 static int delete_self(struct tdb_context
*tdb
, TDB_DATA key
, TDB_DATA data
,
62 ok1(tdb_delete(tdb
, key
) == TDB_SUCCESS
);
66 int main(int argc
, char *argv
[])
68 struct tdb_context
*tdb
;
70 union tdb_attribute hsize
;
72 hsize
.base
.attr
= TDB_ATTRIBUTE_TDB1_HASHSIZE
;
73 hsize
.base
.next
= &tap_log_attr
;
74 hsize
.tdb1_hashsize
.hsize
= 1024;
77 tdb
= tdb_open("run-no-lock-during-traverse.tdb1",
78 TDB_VERSION1
, O_CREAT
|O_TRUNC
|O_RDWR
,
82 ok1(prepare_entries(tdb
));
83 ok1(locking_errors1
== 0);
84 ok1(tdb_lockall(tdb
) == 0);
85 ok1(locking_errors1
== 0);
86 ok1(tdb_traverse(tdb
, delete_other
, &errors
) >= 0);
88 ok1(locking_errors1
== 0);
91 ok1(prepare_entries(tdb
));
92 ok1(locking_errors1
== 0);
93 ok1(tdb_lockall(tdb
) == 0);
94 ok1(locking_errors1
== 0);
95 ok1(tdb_traverse(tdb
, delete_self
, NULL
) == NUM_ENTRIES
);
96 ok1(locking_errors1
== 0);
99 ok1(prepare_entries(tdb
));
100 ok1(locking_errors1
== 0);
101 ok1(tdb_lockall(tdb
) == 0);
102 ok1(locking_errors1
== 0);
104 ok1(locking_errors1
== 0);
107 ok1(tdb_close(tdb
) == 0);
109 return exit_status();