2 Unix SMB/CIFS implementation.
4 Copyright (C) Volker Lendecke 2012
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "torture/proto.h"
23 #ifdef CLUSTER_SUPPORT
25 #include "ctdb_conn.h"
26 #include "lib/util/tevent_unix.h"
29 #ifdef HAVE_CTDB_PROTOCOL_H
30 #include "ctdb_protocol.h"
32 #include "ctdb_private.h"
37 struct ctdb_conn_test_state
{
38 struct tevent_context
*ev
;
39 struct ctdb_conn
*conn
;
40 struct ctdb_msg_channel
*channel
;
44 static void ctdb_conn_test_got_conn(struct tevent_req
*subreq
);
45 static void ctdb_conn_test_got_pnn(struct tevent_req
*subreq
);
46 static void ctdb_conn_test_got_channel(struct tevent_req
*subreq
);
47 static void ctdb_conn_test_got_msg(struct tevent_req
*subreq
);
48 static void ctdb_conn_test_msg_sent(struct tevent_req
*subreq
);
50 static struct tevent_req
*ctdb_conn_test_send(TALLOC_CTX
*mem_ctx
,
51 struct tevent_context
*ev
)
53 struct tevent_req
*req
, *subreq
;
54 struct ctdb_conn_test_state
*state
;
56 req
= tevent_req_create(mem_ctx
, &state
, struct ctdb_conn_test_state
);
62 subreq
= ctdb_conn_init_send(mem_ctx
, ev
, lp_ctdbd_socket());
63 if (tevent_req_nomem(subreq
, req
)) {
64 return tevent_req_post(req
, ev
);
66 tevent_req_set_callback(subreq
, ctdb_conn_test_got_conn
, req
);
70 static void ctdb_conn_test_got_conn(struct tevent_req
*subreq
)
72 struct tevent_req
*req
= tevent_req_callback_data(
73 subreq
, struct tevent_req
);
74 struct ctdb_conn_test_state
*state
= tevent_req_data(
75 req
, struct ctdb_conn_test_state
);
78 ret
= ctdb_conn_init_recv(subreq
, state
, &state
->conn
);
80 if (tevent_req_error(req
, ret
)) {
83 subreq
= ctdb_conn_control_send(state
, state
->ev
, state
->conn
,
85 CTDB_CONTROL_GET_PNN
, 0, 0, NULL
, 0);
86 if (tevent_req_nomem(subreq
, req
)) {
89 tevent_req_set_callback(subreq
, ctdb_conn_test_got_pnn
, req
);
92 static void ctdb_conn_test_got_pnn(struct tevent_req
*subreq
)
94 struct tevent_req
*req
= tevent_req_callback_data(
95 subreq
, struct tevent_req
);
96 struct ctdb_conn_test_state
*state
= tevent_req_data(
97 req
, struct ctdb_conn_test_state
);
99 struct ctdb_reply_control
*reply
;
101 ret
= ctdb_conn_control_recv(subreq
, talloc_tos(), &reply
);
103 if (tevent_req_error(req
, ret
)) {
106 printf("vnn=%d\n", (int)reply
->status
);
108 subreq
= ctdb_msg_channel_init_send(
109 state
, state
->ev
, lp_ctdbd_socket(), 999999);
110 if (tevent_req_nomem(subreq
, req
)) {
113 tevent_req_set_callback(subreq
, ctdb_conn_test_got_channel
, req
);
116 static void ctdb_conn_test_got_channel(struct tevent_req
*subreq
)
118 struct tevent_req
*req
= tevent_req_callback_data(
119 subreq
, struct tevent_req
);
120 struct ctdb_conn_test_state
*state
= tevent_req_data(
121 req
, struct ctdb_conn_test_state
);
124 ret
= ctdb_msg_channel_init_recv(subreq
, state
, &state
->channel
);
126 if (tevent_req_error(req
, ret
)) {
130 subreq
= ctdb_msg_read_send(state
, state
->ev
, state
->channel
);
131 if (tevent_req_nomem(subreq
, req
)) {
134 tevent_req_set_callback(subreq
, ctdb_conn_test_got_msg
, req
);
138 subreq
= ctdb_conn_msg_write_send(
139 state
, state
->ev
, state
->conn
, CTDB_CURRENT_NODE
, 999999,
140 (uint8_t *)&state
->msgno
, sizeof(state
->msgno
));
141 if (tevent_req_nomem(subreq
, req
)) {
144 tevent_req_set_callback(subreq
, ctdb_conn_test_msg_sent
, req
);
147 static void ctdb_conn_test_got_msg(struct tevent_req
*subreq
)
149 struct tevent_req
*req
= tevent_req_callback_data(
150 subreq
, struct tevent_req
);
151 struct ctdb_conn_test_state
*state
= tevent_req_data(
152 req
, struct ctdb_conn_test_state
);
157 ret
= ctdb_msg_read_recv(subreq
, talloc_tos(), &buf
, &buf_len
);
159 if (tevent_req_error(req
, ret
)) {
162 if (buf_len
!= sizeof(int)) {
163 printf("got invalid msg\n");
164 tevent_req_error(req
, EINVAL
);
167 memcpy(&ret
, buf
, buf_len
);
168 printf("got msg %d\n", ret
);
170 tevent_req_done(req
);
174 subreq
= ctdb_msg_read_send(state
, state
->ev
, state
->channel
);
175 if (tevent_req_nomem(subreq
, req
)) {
178 tevent_req_set_callback(subreq
, ctdb_conn_test_got_msg
, req
);
181 static void ctdb_conn_test_msg_sent(struct tevent_req
*subreq
)
183 struct tevent_req
*req
= tevent_req_callback_data(
184 subreq
, struct tevent_req
);
185 struct ctdb_conn_test_state
*state
= tevent_req_data(
186 req
, struct ctdb_conn_test_state
);
189 ret
= ctdb_conn_msg_write_recv(subreq
);
191 if (tevent_req_error(req
, ret
)) {
196 if (state
->msgno
>= 10) {
200 subreq
= ctdb_conn_msg_write_send(
201 state
, state
->ev
, state
->conn
, CTDB_CURRENT_NODE
, 999999,
202 (uint8_t *)&state
->msgno
, sizeof(state
->msgno
));
203 if (tevent_req_nomem(subreq
, req
)) {
206 tevent_req_set_callback(subreq
, ctdb_conn_test_msg_sent
, req
);
209 static int ctdb_conn_test_recv(struct tevent_req
*req
)
212 if (tevent_req_is_unix_error(req
, &err
)) {
218 bool run_ctdb_conn(int dummy
)
220 struct tevent_context
*ev
;
221 struct tevent_req
*req
;
224 ev
= samba_tevent_context_init(talloc_tos());
226 fprintf(stderr
, "tevent_context_init failed\n");
229 req
= ctdb_conn_test_send(ev
, ev
);
231 fprintf(stderr
, "ctdb_conn_test_send failed\n");
234 if (!tevent_req_poll(req
, ev
)) {
235 fprintf(stderr
, "tevent_req_poll failed\n");
238 ret
= ctdb_conn_test_recv(req
);
240 printf("ctdb_conn_test returned %s\n",
241 ret
? strerror(ret
) : "success");
246 #else /* CLUSTER_SUPPORT */
248 bool run_ctdb_conn(int dummy
)