3 #include "tdb1-lock-tracking.h"
5 #define fcntl fcntl_with_lockcheck1
7 #include "tdb2-source.h"
8 #include "tap-interface.h"
14 #define NUM_ENTRIES 10
16 static bool prepare_entries(struct tdb_context *tdb)
21 for (i = 0; i < NUM_ENTRIES; i++) {
22 key.dsize = sizeof(i);
23 key.dptr = (void *)&i;
24 data = tdb_mkdata("world", strlen("world"));
26 if (tdb_store(tdb, key, data, 0) != TDB_SUCCESS)
32 static void delete_entries(struct tdb_context *tdb)
37 for (i = 0; i < NUM_ENTRIES; i++) {
38 key.dsize = sizeof(i);
39 key.dptr = (void *)&i;
41 ok1(tdb_delete(tdb, key) == TDB_SUCCESS);
45 /* We don't know how many times this will run. */
46 static int delete_other(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data,
50 memcpy(&i, key.dptr, 4);
51 i = (i + 1) % NUM_ENTRIES;
52 key.dptr = (void *)&i;
53 if (tdb_delete(tdb, key) != TDB_SUCCESS)
54 (*(int *)private_data)++;
58 static int delete_self(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data,
61 ok1(tdb_delete(tdb, key) == TDB_SUCCESS);
65 int main(int argc, char *argv[])
67 struct tdb_context *tdb;
69 union tdb_attribute hsize;
71 hsize.base.attr = TDB_ATTRIBUTE_TDB1_HASHSIZE;
72 hsize.base.next = &tap_log_attr;
73 hsize.tdb1_hashsize.hsize = 1024;
76 tdb = tdb_open("run-no-lock-during-traverse.tdb1",
77 TDB_VERSION1, O_CREAT|O_TRUNC|O_RDWR,
81 ok1(prepare_entries(tdb));
82 ok1(locking_errors1 == 0);
83 ok1(tdb_lockall(tdb) == 0);
84 ok1(locking_errors1 == 0);
85 ok1(tdb_traverse(tdb, delete_other, &errors) >= 0);
87 ok1(locking_errors1 == 0);
90 ok1(prepare_entries(tdb));
91 ok1(locking_errors1 == 0);
92 ok1(tdb_lockall(tdb) == 0);
93 ok1(locking_errors1 == 0);
94 ok1(tdb_traverse(tdb, delete_self, NULL) == NUM_ENTRIES);
95 ok1(locking_errors1 == 0);
98 ok1(prepare_entries(tdb));
99 ok1(locking_errors1 == 0);
100 ok1(tdb_lockall(tdb) == 0);
101 ok1(locking_errors1 == 0);
103 ok1(locking_errors1 == 0);
106 ok1(tdb_close(tdb) == 0);
108 return exit_status();