Whamcloud - gitweb
LU-10973 lnet: initial LUTF C infrastructure
[fs/lustre-release.git] / lustre / tests / lutf / src / lutf_agent.h
1 #ifndef LUTF_AGENTS_H
2 #define LUTF_AGENTS_H
3
4 #include "lutf_common.h"
5
6 #define MAX_NUM_AGENTS          1024
7 #define HB_TO                   2
8
9 struct cYAML;
10
11 #define LUTF_AGENT_STATE_ALIVE (1 << 0)
12 #define LUTF_AGENT_HB_CHANNEL_CONNECTED (1 << 1)
13 #define LUTF_AGENT_RPC_CHANNEL_CONNECTED (1 << 2)
14 #define LUTF_AGENT_WORK_IN_PROGRESS (1 << 3)
15 #define LUTF_AGENT_ZOMBIE (1 << 4)
16
17 typedef struct lutf_agent_blk_s {
18         pthread_mutex_t mutex;
19         unsigned int id;
20         unsigned int version;
21         unsigned int telnet_port;
22         unsigned int listen_port;
23         char name[MAX_STR_LEN];
24         char hostname[MAX_STR_LEN];
25         int iFileDesc;
26         int iRpcFd;
27         struct timeval time_stamp;
28         struct sockaddr_in addr;
29         unsigned int state;
30         unsigned int ref_count;
31         lutf_type_t node_type;
32 } lutf_agent_blk_t;
33
34 /* lutf_agent_get_highest_fd
35  *      Find the highest connected FD in all connected agents.
36  */
37 int lutf_agent_get_highest_fd(void);
38
39 /* agent_state2str
40  *      print agent state
41  */
42 char *agent_state2str(lutf_agent_blk_t *agent);
43
44 /* get_local_ip
45  *   gets the local IP address being used to send messages to the master
46  */
47 char *get_local_ip();
48
49 /*
50  * get_next_active_agent
51  *      given an index start searching from that point on to find an
52  *      active agent.
53  *      To reset the loop start the index from 0
54  */
55 int get_next_active_agent(int idx, lutf_agent_blk_t **out);
56
57 /*
58  * find_agent_blk_by_id
59  *      Find the agent blk given an internal ID
60  *      Agent ref-count is incremented
61  */
62 lutf_agent_blk_t *find_agent_blk_by_id(int idx);
63
64 /*
65  * find_agent_blk_by_ip
66  *      Find the agent blk given its IP address
67  *      Agent ref-count is incremented
68  */
69 lutf_agent_blk_t *find_agent_blk_by_ip(char *ip);
70
71 /*
72  * find_agent_blk_by_name
73  *      Find the agent blk given its name
74  *      Agent ref-count is incremented
75  */
76 lutf_agent_blk_t *find_agent_blk_by_name(char *name);
77
78 /*
79  * find_create_agent_blk_by_addr
80  *      return an agent block with this address or create a new one
81  */
82 lutf_agent_blk_t *find_create_agent_blk_by_addr(struct sockaddr_in *addr);
83
84 /*
85  * find_free_agent_blk
86  *      Find a free agent block
87  */
88 lutf_agent_blk_t *find_free_agent_blk(struct sockaddr_in *addr);
89
90 /*
91  * free_agent_blk
92  *      Free an agent blk that no longer is needed
93  */
94 void free_agent_blk(int id);
95
96 /*
97  * acquire_agent_blk
98  *      acquire the agent for work
99  */
100 void acquire_agent_blk(lutf_agent_blk_t *agent);
101
102 /*
103  * release_agent_blk
104  *      Release the agent blk
105  */
106 void release_agent_blk(lutf_agent_blk_t *agent);
107
108 /*
109  * agent_ip2str
110  *      Returns the ip string representation
111  */
112 char *agent_ip2str(lutf_agent_blk_t *agent);
113
114 /*
115  * agent_hb_check
116  *      Given a time struct insure that the agent doesn't exceed the HB
117  *      time.
118  */
119 void agent_hb_check(struct timeval *t, lutf_type_t whoami);
120
121 /*
122  * agent_disable_hb
123  *      Disables the HB
124  */
125 void agent_disable_hb(void);
126
127 /*
128  * agent_enable_hb
129  *      Enables the HB
130  */
131 void agent_enable_hb(void);
132
133 /*
134  * get the number of registered agents
135  */
136 int get_num_agents(void);
137
138 /*
139  * Connect to masterIP:masterPort and get the number of agents connected
140  * to the master
141  */
142 int get_num_agents_remote(char *masterIP, int masterPort);
143
144 /*
145  * wait for the agents specified to be connected. If we don't get the full
146  * list within the time specified then fail
147  */
148 lutf_rc_t wait_for_agents(struct cYAML *agents, int timeout);
149
150 /*
151  * set_agent_state
152  *
153  * convenience function to set the agent state
154  */
155 void set_agent_state(lutf_agent_blk_t *agent, unsigned int state);
156
157 /*
158  * unset_agent_state
159  *
160  * unset the state and check if the agent is a zombie and
161  * it has not pending work. If so then free it
162  */
163 void unset_agent_state(lutf_agent_blk_t *agent, unsigned int state);
164
165 /*
166  * lutf_send_rpc
167  *   send an RPC message and wait for the RPC response
168  *   RPCs always come in request/response pairs. This function will send
169  *   the request and will block until it gets the response. If it doesn't
170  *   get a response in the specified timeout it'll fail.
171  *   Parameters:
172  *      target: name of the agent to send to
173  *      yaml: NULL terminated string to send to the target
174  *      timeout: to wait for response
175  *      rsp: rpc response
176  *
177  *  Return:
178  *     Returns a string YAML block
179  */
180 lutf_rc_t lutf_send_rpc(char *agent, char *yaml, int timeout, char **rsp);
181
182 /*
183  * lutf_send_rpc_rsp
184  *   send a response to the RPC origin.
185  *   Parameters:
186  *      target: name of the agent to send to
187  *      yaml: NULL terminated string to send to the target
188  */
189 lutf_rc_t lutf_send_rpc_rsp(char *agent, char *yaml);
190
191 /*
192  * agent_init
193  *      Initialize the agent module
194  */
195 void agent_init(void);
196
197 #endif /* LUTF_AGENTS_H */