1 #include "lock-tracking.h"
2 #include "../common/tdb_private.h"
3 #define fcntl fcntl_with_lockcheck
4 #include "../common/io.c"
5 #include "../common/tdb.c"
6 #include "../common/lock.c"
7 #include "../common/freelist.c"
8 #include "../common/traverse.c"
9 #include "../common/transaction.c"
10 #include "../common/error.c"
11 #include "../common/open.c"
12 #include "../common/check.c"
13 #include "../common/hash.c"
14 #include "../common/mutex.c"
15 #include "tap-interface.h"
16 #undef fcntl_with_lockcheck
19 #include "external-agent.h"
22 static struct agent *agent;
24 static bool correct_key(TDB_DATA key)
26 return key.dsize == strlen("hi")
27 && memcmp(key.dptr, "hi", key.dsize) == 0;
30 static bool correct_data(TDB_DATA data)
32 return data.dsize == strlen("world")
33 && memcmp(data.dptr, "world", data.dsize) == 0;
36 static int traverse(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data,
39 ok1(correct_key(key));
40 ok1(correct_data(data));
44 int main(int argc, char *argv[])
46 struct tdb_context *tdb;
50 agent = prepare_external_agent();
52 tdb = tdb_open_ex("run-traverse-in-transaction.tdb",
53 1024, TDB_CLEAR_IF_FIRST, O_CREAT|O_TRUNC|O_RDWR,
54 0600, &taplogctx, NULL);
57 key.dsize = strlen("hi");
58 key.dptr = discard_const_p(uint8_t, "hi");
59 data.dptr = discard_const_p(uint8_t, "world");
60 data.dsize = strlen("world");
62 ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0);
64 ok1(external_agent_operation(agent, OPEN, tdb_name(tdb)) == SUCCESS);
66 ok1(tdb_transaction_start(tdb) == 0);
67 ok1(external_agent_operation(agent, TRANSACTION_START, tdb_name(tdb))
68 == WOULD_HAVE_BLOCKED);
69 tdb_traverse(tdb, traverse, NULL);
71 /* That should *not* release the transaction lock! */
72 ok1(external_agent_operation(agent, TRANSACTION_START, tdb_name(tdb))
73 == WOULD_HAVE_BLOCKED);
74 tdb_traverse_read(tdb, traverse, NULL);
76 /* That should *not* release the transaction lock! */
77 ok1(external_agent_operation(agent, TRANSACTION_START, tdb_name(tdb))
78 == WOULD_HAVE_BLOCKED);
79 ok1(tdb_transaction_commit(tdb) == 0);
80 /* Now we should be fine. */
81 ok1(external_agent_operation(agent, TRANSACTION_START, tdb_name(tdb))