summaryrefslogtreecommitdiff
path: root/lib/tdb2/test/external-agent.h
blob: c4cd2b148d0f5a4fd293a8ba6b3d1d54f90c907f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#ifndef TDB2_TEST_EXTERNAL_AGENT_H
#define TDB2_TEST_EXTERNAL_AGENT_H

/* For locking tests, we need a different process to try things at
 * various times. */
enum operation {
	OPEN,
	OPEN_WITH_HOOK,
	FETCH,
	STORE,
	TRANSACTION_START,
	TRANSACTION_COMMIT,
	NEEDS_RECOVERY,
	CHECK,
	SEND_SIGNAL,
	CLOSE,
};

/* Do this before doing any tdb stuff.  Return handle, or -1. */
struct agent *prepare_external_agent(void);

enum agent_return {
	SUCCESS,
	WOULD_HAVE_BLOCKED,
	AGENT_DIED,
	FAILED, /* For fetch, or NEEDS_RECOVERY */
	OTHER_FAILURE,
};

/* Ask the external agent to try to do an operation.
 * name == tdb name for OPEN/OPEN_WITH_CLEAR_IF_FIRST,
 * record name for FETCH/STORE (store stores name as data too)
 */
enum agent_return external_agent_operation(struct agent *handle,
					   enum operation op,
					   const char *name);

/* Hook into free() on tdb_data in external agent. */
extern void (*external_agent_free)(void *);

/* Mapping enum -> string. */
const char *agent_return_name(enum agent_return ret);
const char *operation_name(enum operation op);

void free_external_agent(struct agent *agent);

/* Internal use: */
struct tdb_context;
enum agent_return external_agent_needs_rec(struct tdb_context *tdb);

#endif /* TDB2_TEST_EXTERNAL_AGENT_H */