Bug Summary

File:rpc/rpc-lib/src/rpc-clnt.c
Location:line 193, column 17
Description:Function call argument is an uninitialized value

Annotated Source Code

1/*
2 Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com>
3 This file is part of GlusterFS.
4
5 This file is licensed to you under your choice of the GNU Lesser
6 General Public License, version 3 or any later version (LGPLv3 or
7 later), or the GNU General Public License, version 2 (GPLv2), in all
8 cases as published by the Free Software Foundation.
9*/
10
11
12#ifndef _CONFIG_H
13#define _CONFIG_H
14#include "config.h"
15#endif
16
17#define RPC_CLNT_DEFAULT_REQUEST_COUNT512 512
18
19#include "rpc-clnt.h"
20#include "byte-order.h"
21#include "xdr-rpcclnt.h"
22#include "rpc-transport.h"
23#include "protocol-common.h"
24#include "mem-pool.h"
25#include "xdr-rpc.h"
26#include "rpc-common-xdr.h"
27
28void
29rpc_clnt_reply_deinit (struct rpc_req *req, struct mem_pool *pool);
30
31uint64_t
32rpc_clnt_new_callid (struct rpc_clnt *clnt)
33{
34 uint64_t callid = 0;
35
36 pthread_mutex_lock (&clnt->lock);
37 {
38 callid = ++clnt->xid;
39 }
40 pthread_mutex_unlock (&clnt->lock);
41
42 return callid;
43}
44
45
46struct saved_frame *
47__saved_frames_get_timedout (struct saved_frames *frames, uint32_t timeout,
48 struct timeval *current)
49{
50 struct saved_frame *bailout_frame = NULL((void*)0), *tmp = NULL((void*)0);
51
52 if (!list_empty(&frames->sf.list)) {
53 tmp = list_entry (frames->sf.list.next, typeof (*tmp), list)((typeof (*tmp) *)((char *)(frames->sf.list.next)-(unsigned
long)(&((typeof (*tmp) *)0)->list)))
;
54 if ((tmp->saved_at.tv_sec + timeout) < current->tv_sec) {
55 bailout_frame = tmp;
56 list_del_init (&bailout_frame->list);
57 frames->count--;
58 }
59 }
60
61 return bailout_frame;
62}
63
64static int
65_is_lock_fop (struct saved_frame *sframe)
66{
67 int fop = 0;
68
69 if (SFRAME_GET_PROGNUM (sframe)(sframe->rpcreq->prog->prognum) == GLUSTER_FOP_PROGRAM1298437 &&
70 SFRAME_GET_PROGVER (sframe)(sframe->rpcreq->prog->progver) == GLUSTER_FOP_VERSION330)
71 fop = SFRAME_GET_PROCNUM (sframe)(sframe->rpcreq->procnum);
72
73 return ((fop == GFS3_OP_LK) ||
74 (fop == GFS3_OP_INODELK) ||
75 (fop == GFS3_OP_FINODELK) ||
76 (fop == GFS3_OP_ENTRYLK) ||
77 (fop == GFS3_OP_FENTRYLK));
78}
79
80struct saved_frame *
81__saved_frames_put (struct saved_frames *frames, void *frame,
82 struct rpc_req *rpcreq)
83{
84 struct saved_frame *saved_frame = NULL((void*)0);
85
86 saved_frame = mem_get (rpcreq->conn->rpc_clnt->saved_frames_pool);
87 if (!saved_frame) {
88 goto out;
89 }
90 /* THIS should be saved and set back */
91
92 memset (saved_frame, 0, sizeof (*saved_frame));
93 INIT_LIST_HEAD (&saved_frame->list)do { (&saved_frame->list)->next = (&saved_frame
->list)->prev = &saved_frame->list; } while (0)
;
94
95 saved_frame->capital_this = THIS(*__glusterfs_this_location());
96 saved_frame->frame = frame;
97 saved_frame->rpcreq = rpcreq;
98 gettimeofday (&saved_frame->saved_at, NULL((void*)0));
99
100 if (_is_lock_fop (saved_frame))
101 list_add_tail (&saved_frame->list, &frames->lk_sf.list);
102 else
103 list_add_tail (&saved_frame->list, &frames->sf.list);
104
105 frames->count++;
106
107out:
108 return saved_frame;
109}
110
111
112void
113saved_frames_delete (struct saved_frame *saved_frame,
114 rpc_clnt_connection_t *conn)
115{
116 GF_VALIDATE_OR_GOTO ("rpc-clnt", saved_frame, out)do { if (!saved_frame) { (*__errno_location ()) = 22; do { do
{ if (0) printf ("invalid argument: " "saved_frame"); } while
(0); _gf_log_callingfn ("rpc-clnt", "rpc-clnt.c", __FUNCTION__
, 116, GF_LOG_ERROR, "invalid argument: " "saved_frame"); } while
(0); goto out; } } while (0)
;
117 GF_VALIDATE_OR_GOTO ("rpc-clnt", conn, out)do { if (!conn) { (*__errno_location ()) = 22; do { do { if (
0) printf ("invalid argument: " "conn"); } while (0); _gf_log_callingfn
("rpc-clnt", "rpc-clnt.c", __FUNCTION__, 117, GF_LOG_ERROR, "invalid argument: "
"conn"); } while (0); goto out; } } while (0)
;
118
119 pthread_mutex_lock (&conn->lock);
120 {
121 list_del_init (&saved_frame->list);
122 conn->saved_frames->count--;
123 }
124 pthread_mutex_unlock (&conn->lock);
125
126 if (saved_frame->rpcreq != NULL((void*)0)) {
127 rpc_clnt_reply_deinit (saved_frame->rpcreq,
128 conn->rpc_clnt->reqpool);
129 }
130
131 mem_put (saved_frame);
132out:
133 return;
134}
135
136
137static void
138call_bail (void *data)
139{
140 struct rpc_clnt *clnt = NULL((void*)0);
141 rpc_clnt_connection_t *conn = NULL((void*)0);
142 struct timeval current;
143 struct list_head list;
144 struct saved_frame *saved_frame = NULL((void*)0);
145 struct saved_frame *trav = NULL((void*)0);
146 struct saved_frame *tmp = NULL((void*)0);
147 char frame_sent[256] = {0,};
148 struct timeval timeout = {0,};
149 struct iovec iov = {0,};
150
151 GF_VALIDATE_OR_GOTO ("client", data, out)do { if (!data) { (*__errno_location ()) = 22; do { do { if (
0) printf ("invalid argument: " "data"); } while (0); _gf_log_callingfn
("client", "rpc-clnt.c", __FUNCTION__, 151, GF_LOG_ERROR, "invalid argument: "
"data"); } while (0); goto out; } } while (0)
;
152
153 clnt = data;
154
155 conn = &clnt->conn;
156
157 gettimeofday (&current, NULL((void*)0));
158 INIT_LIST_HEAD (&list)do { (&list)->next = (&list)->prev = &list;
} while (0)
;
159
160 pthread_mutex_lock (&conn->lock);
161 {
162 /* Chaining to get call-always functionality from
163 call-once timer */
164 if (conn->timer) {
1
Taking false branch
165 timeout.tv_sec = 10;
166 timeout.tv_usec = 0;
167
168 gf_timer_call_cancel (clnt->ctx, conn->timer);
169 conn->timer = gf_timer_call_after (clnt->ctx,
170 timeout,
171 call_bail,
172 (void *) clnt);
173
174 if (conn->timer == NULL((void*)0)) {
175 gf_log (conn->trans->name, GF_LOG_WARNING,do { do { if (0) printf ("Cannot create bailout timer"); } while
(0); _gf_log (conn->trans->name, "rpc-clnt.c", __FUNCTION__
, 176, GF_LOG_WARNING, "Cannot create bailout timer"); } while
(0)
176 "Cannot create bailout timer")do { do { if (0) printf ("Cannot create bailout timer"); } while
(0); _gf_log (conn->trans->name, "rpc-clnt.c", __FUNCTION__
, 176, GF_LOG_WARNING, "Cannot create bailout timer"); } while
(0)
;
177 }
178 }
179
180 do {
3
Loop condition is false. Exiting loop
181 saved_frame =
182 __saved_frames_get_timedout (conn->saved_frames,
183 conn->frame_timeout,
184 &current);
185 if (saved_frame)
2
Taking false branch
186 list_add (&saved_frame->list, &list);
187
188 } while (saved_frame);
189 }
190 pthread_mutex_unlock (&conn->lock);
191
192 list_for_each_entry_safe (trav, tmp, &list, list)for (trav = ((typeof(*trav) *)((char *)((&list)->next)
-(unsigned long)(&((typeof(*trav) *)0)->list))), tmp =
((typeof(*trav) *)((char *)(trav->list.next)-(unsigned long
)(&((typeof(*trav) *)0)->list))); &trav->list !=
(&list); trav = tmp, tmp = ((typeof(*tmp) *)((char *)(tmp
->list.next)-(unsigned long)(&((typeof(*tmp) *)0)->
list))))
{
193 gf_time_fmt (frame_sent, sizeof frame_sent,
4
Function call argument is an uninitialized value
194 trav->saved_at.tv_sec, gf_timefmt_FT);
195 snprintf (frame_sent + strlen (frame_sent),
196 256 - strlen (frame_sent),
197 ".%"GF_PRI_SUSECONDS"06ld", trav->saved_at.tv_usec);
198
199 gf_log (conn->trans->name, GF_LOG_ERROR,do { do { if (0) printf ("bailing out frame type(%s) op(%s(%d)) xid = 0x%ux "
"sent = %s. timeout = %d", trav->rpcreq->prog->progname
, (trav->rpcreq->prog->procnames) ? trav->rpcreq->
prog->procnames[trav->rpcreq->procnum] : "--", trav->
rpcreq->procnum, trav->rpcreq->xid, frame_sent, conn
->frame_timeout); } while (0); _gf_log (conn->trans->
name, "rpc-clnt.c", __FUNCTION__, 207, GF_LOG_ERROR, "bailing out frame type(%s) op(%s(%d)) xid = 0x%ux "
"sent = %s. timeout = %d", trav->rpcreq->prog->progname
, (trav->rpcreq->prog->procnames) ? trav->rpcreq->
prog->procnames[trav->rpcreq->procnum] : "--", trav->
rpcreq->procnum, trav->rpcreq->xid, frame_sent, conn
->frame_timeout); } while (0)
200 "bailing out frame type(%s) op(%s(%d)) xid = 0x%ux "do { do { if (0) printf ("bailing out frame type(%s) op(%s(%d)) xid = 0x%ux "
"sent = %s. timeout = %d", trav->rpcreq->prog->progname
, (trav->rpcreq->prog->procnames) ? trav->rpcreq->
prog->procnames[trav->rpcreq->procnum] : "--", trav->
rpcreq->procnum, trav->rpcreq->xid, frame_sent, conn
->frame_timeout); } while (0); _gf_log (conn->trans->
name, "rpc-clnt.c", __FUNCTION__, 207, GF_LOG_ERROR, "bailing out frame type(%s) op(%s(%d)) xid = 0x%ux "
"sent = %s. timeout = %d", trav->rpcreq->prog->progname
, (trav->rpcreq->prog->procnames) ? trav->rpcreq->
prog->procnames[trav->rpcreq->procnum] : "--", trav->
rpcreq->procnum, trav->rpcreq->xid, frame_sent, conn
->frame_timeout); } while (0)
201 "sent = %s. timeout = %d",do { do { if (0) printf ("bailing out frame type(%s) op(%s(%d)) xid = 0x%ux "
"sent = %s. timeout = %d", trav->rpcreq->prog->progname
, (trav->rpcreq->prog->procnames) ? trav->rpcreq->
prog->procnames[trav->rpcreq->procnum] : "--", trav->
rpcreq->procnum, trav->rpcreq->xid, frame_sent, conn
->frame_timeout); } while (0); _gf_log (conn->trans->
name, "rpc-clnt.c", __FUNCTION__, 207, GF_LOG_ERROR, "bailing out frame type(%s) op(%s(%d)) xid = 0x%ux "
"sent = %s. timeout = %d", trav->rpcreq->prog->progname
, (trav->rpcreq->prog->procnames) ? trav->rpcreq->
prog->procnames[trav->rpcreq->procnum] : "--", trav->
rpcreq->procnum, trav->rpcreq->xid, frame_sent, conn
->frame_timeout); } while (0)
202 trav->rpcreq->prog->progname,do { do { if (0) printf ("bailing out frame type(%s) op(%s(%d)) xid = 0x%ux "
"sent = %s. timeout = %d", trav->rpcreq->prog->progname
, (trav->rpcreq->prog->procnames) ? trav->rpcreq->
prog->procnames[trav->rpcreq->procnum] : "--", trav->
rpcreq->procnum, trav->rpcreq->xid, frame_sent, conn
->frame_timeout); } while (0); _gf_log (conn->trans->
name, "rpc-clnt.c", __FUNCTION__, 207, GF_LOG_ERROR, "bailing out frame type(%s) op(%s(%d)) xid = 0x%ux "
"sent = %s. timeout = %d", trav->rpcreq->prog->progname
, (trav->rpcreq->prog->procnames) ? trav->rpcreq->
prog->procnames[trav->rpcreq->procnum] : "--", trav->
rpcreq->procnum, trav->rpcreq->xid, frame_sent, conn
->frame_timeout); } while (0)
203 (trav->rpcreq->prog->procnames) ?do { do { if (0) printf ("bailing out frame type(%s) op(%s(%d)) xid = 0x%ux "
"sent = %s. timeout = %d", trav->rpcreq->prog->progname
, (trav->rpcreq->prog->procnames) ? trav->rpcreq->
prog->procnames[trav->rpcreq->procnum] : "--", trav->
rpcreq->procnum, trav->rpcreq->xid, frame_sent, conn
->frame_timeout); } while (0); _gf_log (conn->trans->
name, "rpc-clnt.c", __FUNCTION__, 207, GF_LOG_ERROR, "bailing out frame type(%s) op(%s(%d)) xid = 0x%ux "
"sent = %s. timeout = %d", trav->rpcreq->prog->progname
, (trav->rpcreq->prog->procnames) ? trav->rpcreq->
prog->procnames[trav->rpcreq->procnum] : "--", trav->
rpcreq->procnum, trav->rpcreq->xid, frame_sent, conn
->frame_timeout); } while (0)
204 trav->rpcreq->prog->procnames[trav->rpcreq->procnum] :do { do { if (0) printf ("bailing out frame type(%s) op(%s(%d)) xid = 0x%ux "
"sent = %s. timeout = %d", trav->rpcreq->prog->progname
, (trav->rpcreq->prog->procnames) ? trav->rpcreq->
prog->procnames[trav->rpcreq->procnum] : "--", trav->
rpcreq->procnum, trav->rpcreq->xid, frame_sent, conn
->frame_timeout); } while (0); _gf_log (conn->trans->
name, "rpc-clnt.c", __FUNCTION__, 207, GF_LOG_ERROR, "bailing out frame type(%s) op(%s(%d)) xid = 0x%ux "
"sent = %s. timeout = %d", trav->rpcreq->prog->progname
, (trav->rpcreq->prog->procnames) ? trav->rpcreq->
prog->procnames[trav->rpcreq->procnum] : "--", trav->
rpcreq->procnum, trav->rpcreq->xid, frame_sent, conn
->frame_timeout); } while (0)
205 "--",do { do { if (0) printf ("bailing out frame type(%s) op(%s(%d)) xid = 0x%ux "
"sent = %s. timeout = %d", trav->rpcreq->prog->progname
, (trav->rpcreq->prog->procnames) ? trav->rpcreq->
prog->procnames[trav->rpcreq->procnum] : "--", trav->
rpcreq->procnum, trav->rpcreq->xid, frame_sent, conn
->frame_timeout); } while (0); _gf_log (conn->trans->
name, "rpc-clnt.c", __FUNCTION__, 207, GF_LOG_ERROR, "bailing out frame type(%s) op(%s(%d)) xid = 0x%ux "
"sent = %s. timeout = %d", trav->rpcreq->prog->progname
, (trav->rpcreq->prog->procnames) ? trav->rpcreq->
prog->procnames[trav->rpcreq->procnum] : "--", trav->
rpcreq->procnum, trav->rpcreq->xid, frame_sent, conn
->frame_timeout); } while (0)
206 trav->rpcreq->procnum, trav->rpcreq->xid, frame_sent,do { do { if (0) printf ("bailing out frame type(%s) op(%s(%d)) xid = 0x%ux "
"sent = %s. timeout = %d", trav->rpcreq->prog->progname
, (trav->rpcreq->prog->procnames) ? trav->rpcreq->
prog->procnames[trav->rpcreq->procnum] : "--", trav->
rpcreq->procnum, trav->rpcreq->xid, frame_sent, conn
->frame_timeout); } while (0); _gf_log (conn->trans->
name, "rpc-clnt.c", __FUNCTION__, 207, GF_LOG_ERROR, "bailing out frame type(%s) op(%s(%d)) xid = 0x%ux "
"sent = %s. timeout = %d", trav->rpcreq->prog->progname
, (trav->rpcreq->prog->procnames) ? trav->rpcreq->
prog->procnames[trav->rpcreq->procnum] : "--", trav->
rpcreq->procnum, trav->rpcreq->xid, frame_sent, conn
->frame_timeout); } while (0)
207 conn->frame_timeout)do { do { if (0) printf ("bailing out frame type(%s) op(%s(%d)) xid = 0x%ux "
"sent = %s. timeout = %d", trav->rpcreq->prog->progname
, (trav->rpcreq->prog->procnames) ? trav->rpcreq->
prog->procnames[trav->rpcreq->procnum] : "--", trav->
rpcreq->procnum, trav->rpcreq->xid, frame_sent, conn
->frame_timeout); } while (0); _gf_log (conn->trans->
name, "rpc-clnt.c", __FUNCTION__, 207, GF_LOG_ERROR, "bailing out frame type(%s) op(%s(%d)) xid = 0x%ux "
"sent = %s. timeout = %d", trav->rpcreq->prog->progname
, (trav->rpcreq->prog->procnames) ? trav->rpcreq->
prog->procnames[trav->rpcreq->procnum] : "--", trav->
rpcreq->procnum, trav->rpcreq->xid, frame_sent, conn
->frame_timeout); } while (0)
;
208
209 clnt = rpc_clnt_ref (clnt);
210 trav->rpcreq->rpc_status = -1;
211 trav->rpcreq->cbkfn (trav->rpcreq, &iov, 1, trav->frame);
212
213 rpc_clnt_reply_deinit (trav->rpcreq, clnt->reqpool);
214 clnt = rpc_clnt_unref (clnt);
215 list_del_init (&trav->list);
216 mem_put (trav);
217 }
218out:
219 return;
220}
221
222
223/* to be called with conn->lock held */
224struct saved_frame *
225__save_frame (struct rpc_clnt *rpc_clnt, call_frame_t *frame,
226 struct rpc_req *rpcreq)
227{
228 rpc_clnt_connection_t *conn = NULL((void*)0);
229 struct timeval timeout = {0, };
230 struct saved_frame *saved_frame = NULL((void*)0);
231
232 conn = &rpc_clnt->conn;
233
234 saved_frame = __saved_frames_put (conn->saved_frames, frame, rpcreq);
235
236 if (saved_frame == NULL((void*)0)) {
237 goto out;
238 }
239
240 /* TODO: make timeout configurable */
241 if (conn->timer == NULL((void*)0)) {
242 timeout.tv_sec = 10;
243 timeout.tv_usec = 0;
244 conn->timer = gf_timer_call_after (rpc_clnt->ctx,
245 timeout,
246 call_bail,
247 (void *) rpc_clnt);
248 }
249
250out:
251 return saved_frame;
252}
253
254
255struct saved_frames *
256saved_frames_new (void)
257{
258 struct saved_frames *saved_frames = NULL((void*)0);
259
260 saved_frames = GF_CALLOC (1, sizeof (*saved_frames),__gf_calloc (1, sizeof (*saved_frames), gf_common_mt_rpcclnt_savedframe_t
)
261 gf_common_mt_rpcclnt_savedframe_t)__gf_calloc (1, sizeof (*saved_frames), gf_common_mt_rpcclnt_savedframe_t
)
;
262 if (!saved_frames) {
263 return NULL((void*)0);
264 }
265
266 INIT_LIST_HEAD (&saved_frames->sf.list)do { (&saved_frames->sf.list)->next = (&saved_frames
->sf.list)->prev = &saved_frames->sf.list; } while
(0)
;
267 INIT_LIST_HEAD (&saved_frames->lk_sf.list)do { (&saved_frames->lk_sf.list)->next = (&saved_frames
->lk_sf.list)->prev = &saved_frames->lk_sf.list;
} while (0)
;
268
269 return saved_frames;
270}
271
272
273int
274__saved_frame_copy (struct saved_frames *frames, int64_t callid,
275 struct saved_frame *saved_frame)
276{
277 struct saved_frame *tmp = NULL((void*)0);
278 int ret = -1;
279
280 if (!saved_frame) {
281 ret = 0;
282 goto out;
283 }
284
285 list_for_each_entry (tmp, &frames->sf.list, list)for (tmp = ((typeof(*tmp) *)((char *)((&frames->sf.list
)->next)-(unsigned long)(&((typeof(*tmp) *)0)->list
))); &tmp->list != (&frames->sf.list); tmp = ((
typeof(*tmp) *)((char *)(tmp->list.next)-(unsigned long)(&
((typeof(*tmp) *)0)->list))))
{
286 if (tmp->rpcreq->xid == callid) {
287 *saved_frame = *tmp;
288 ret = 0;
289 goto out;
290 }
291 }
292
293 list_for_each_entry (tmp, &frames->lk_sf.list, list)for (tmp = ((typeof(*tmp) *)((char *)((&frames->lk_sf.
list)->next)-(unsigned long)(&((typeof(*tmp) *)0)->
list))); &tmp->list != (&frames->lk_sf.list); tmp
= ((typeof(*tmp) *)((char *)(tmp->list.next)-(unsigned long
)(&((typeof(*tmp) *)0)->list))))
{
294 if (tmp->rpcreq->xid == callid) {
295 *saved_frame = *tmp;
296 ret = 0;
297 goto out;
298 }
299 }
300
301out:
302 return ret;
303}
304
305
306struct saved_frame *
307__saved_frame_get (struct saved_frames *frames, int64_t callid)
308{
309 struct saved_frame *saved_frame = NULL((void*)0);
310 struct saved_frame *tmp = NULL((void*)0);
311
312 list_for_each_entry (tmp, &frames->sf.list, list)for (tmp = ((typeof(*tmp) *)((char *)((&frames->sf.list
)->next)-(unsigned long)(&((typeof(*tmp) *)0)->list
))); &tmp->list != (&frames->sf.list); tmp = ((
typeof(*tmp) *)((char *)(tmp->list.next)-(unsigned long)(&
((typeof(*tmp) *)0)->list))))
{
313 if (tmp->rpcreq->xid == callid) {
314 list_del_init (&tmp->list);
315 frames->count--;
316 saved_frame = tmp;
317 goto out;
318 }
319 }
320
321 list_for_each_entry (tmp, &frames->lk_sf.list, list)for (tmp = ((typeof(*tmp) *)((char *)((&frames->lk_sf.
list)->next)-(unsigned long)(&((typeof(*tmp) *)0)->
list))); &tmp->list != (&frames->lk_sf.list); tmp
= ((typeof(*tmp) *)((char *)(tmp->list.next)-(unsigned long
)(&((typeof(*tmp) *)0)->list))))
{
322 if (tmp->rpcreq->xid == callid) {
323 list_del_init (&tmp->list);
324 frames->count--;
325 saved_frame = tmp;
326 goto out;
327 }
328 }
329
330out:
331 if (saved_frame) {
332 THIS(*__glusterfs_this_location()) = saved_frame->capital_this;
333 }
334
335 return saved_frame;
336}
337
338
339void
340saved_frames_unwind (struct saved_frames *saved_frames)
341{
342 struct saved_frame *trav = NULL((void*)0);
343 struct saved_frame *tmp = NULL((void*)0);
344 char timestr[1024] = {0,};
345 struct iovec iov = {0,};
346
347 list_splice_init (&saved_frames->lk_sf.list, &saved_frames->sf.list);
348
349 list_for_each_entry_safe (trav, tmp, &saved_frames->sf.list, list)for (trav = ((typeof(*trav) *)((char *)((&saved_frames->
sf.list)->next)-(unsigned long)(&((typeof(*trav) *)0)->
list))), tmp = ((typeof(*trav) *)((char *)(trav->list.next
)-(unsigned long)(&((typeof(*trav) *)0)->list))); &
trav->list != (&saved_frames->sf.list); trav = tmp,
tmp = ((typeof(*tmp) *)((char *)(tmp->list.next)-(unsigned
long)(&((typeof(*tmp) *)0)->list))))
{
350 gf_time_fmt (timestr, sizeof timestr,
351 trav->saved_at.tv_sec, gf_timefmt_FT);
352 snprintf (timestr + strlen (timestr),
353 sizeof(timestr) - strlen (timestr),
354 ".%"GF_PRI_SUSECONDS"06ld", trav->saved_at.tv_usec);
355
356 if (!trav->rpcreq || !trav->rpcreq->prog)
357 continue;
358
359 gf_log_callingfn (trav->rpcreq->conn->trans->name,do { do { if (0) printf ("forced unwinding frame type(%s) op(%s(%d)) "
"called at %s (xid=0x%ux)", trav->rpcreq->prog->progname
, ((trav->rpcreq->prog->procnames) ? trav->rpcreq
->prog->procnames[trav->rpcreq->procnum] : "--"),
trav->rpcreq->procnum, timestr, trav->rpcreq->xid
); } while (0); _gf_log_callingfn (trav->rpcreq->conn->
trans->name, "rpc-clnt.c", __FUNCTION__, 368, GF_LOG_ERROR
, "forced unwinding frame type(%s) op(%s(%d)) " "called at %s (xid=0x%ux)"
, trav->rpcreq->prog->progname, ((trav->rpcreq->
prog->procnames) ? trav->rpcreq->prog->procnames[
trav->rpcreq->procnum] : "--"), trav->rpcreq->procnum
, timestr, trav->rpcreq->xid); } while (0)
360 GF_LOG_ERROR,do { do { if (0) printf ("forced unwinding frame type(%s) op(%s(%d)) "
"called at %s (xid=0x%ux)", trav->rpcreq->prog->progname
, ((trav->rpcreq->prog->procnames) ? trav->rpcreq
->prog->procnames[trav->rpcreq->procnum] : "--"),
trav->rpcreq->procnum, timestr, trav->rpcreq->xid
); } while (0); _gf_log_callingfn (trav->rpcreq->conn->
trans->name, "rpc-clnt.c", __FUNCTION__, 368, GF_LOG_ERROR
, "forced unwinding frame type(%s) op(%s(%d)) " "called at %s (xid=0x%ux)"
, trav->rpcreq->prog->progname, ((trav->rpcreq->
prog->procnames) ? trav->rpcreq->prog->procnames[
trav->rpcreq->procnum] : "--"), trav->rpcreq->procnum
, timestr, trav->rpcreq->xid); } while (0)
361 "forced unwinding frame type(%s) op(%s(%d)) "do { do { if (0) printf ("forced unwinding frame type(%s) op(%s(%d)) "
"called at %s (xid=0x%ux)", trav->rpcreq->prog->progname
, ((trav->rpcreq->prog->procnames) ? trav->rpcreq
->prog->procnames[trav->rpcreq->procnum] : "--"),
trav->rpcreq->procnum, timestr, trav->rpcreq->xid
); } while (0); _gf_log_callingfn (trav->rpcreq->conn->
trans->name, "rpc-clnt.c", __FUNCTION__, 368, GF_LOG_ERROR
, "forced unwinding frame type(%s) op(%s(%d)) " "called at %s (xid=0x%ux)"
, trav->rpcreq->prog->progname, ((trav->rpcreq->
prog->procnames) ? trav->rpcreq->prog->procnames[
trav->rpcreq->procnum] : "--"), trav->rpcreq->procnum
, timestr, trav->rpcreq->xid); } while (0)
362 "called at %s (xid=0x%ux)",do { do { if (0) printf ("forced unwinding frame type(%s) op(%s(%d)) "
"called at %s (xid=0x%ux)", trav->rpcreq->prog->progname
, ((trav->rpcreq->prog->procnames) ? trav->rpcreq
->prog->procnames[trav->rpcreq->procnum] : "--"),
trav->rpcreq->procnum, timestr, trav->rpcreq->xid
); } while (0); _gf_log_callingfn (trav->rpcreq->conn->
trans->name, "rpc-clnt.c", __FUNCTION__, 368, GF_LOG_ERROR
, "forced unwinding frame type(%s) op(%s(%d)) " "called at %s (xid=0x%ux)"
, trav->rpcreq->prog->progname, ((trav->rpcreq->
prog->procnames) ? trav->rpcreq->prog->procnames[
trav->rpcreq->procnum] : "--"), trav->rpcreq->procnum
, timestr, trav->rpcreq->xid); } while (0)
363 trav->rpcreq->prog->progname,do { do { if (0) printf ("forced unwinding frame type(%s) op(%s(%d)) "
"called at %s (xid=0x%ux)", trav->rpcreq->prog->progname
, ((trav->rpcreq->prog->procnames) ? trav->rpcreq
->prog->procnames[trav->rpcreq->procnum] : "--"),
trav->rpcreq->procnum, timestr, trav->rpcreq->xid
); } while (0); _gf_log_callingfn (trav->rpcreq->conn->
trans->name, "rpc-clnt.c", __FUNCTION__, 368, GF_LOG_ERROR
, "forced unwinding frame type(%s) op(%s(%d)) " "called at %s (xid=0x%ux)"
, trav->rpcreq->prog->progname, ((trav->rpcreq->
prog->procnames) ? trav->rpcreq->prog->procnames[
trav->rpcreq->procnum] : "--"), trav->rpcreq->procnum
, timestr, trav->rpcreq->xid); } while (0)
364 ((trav->rpcreq->prog->procnames) ?do { do { if (0) printf ("forced unwinding frame type(%s) op(%s(%d)) "
"called at %s (xid=0x%ux)", trav->rpcreq->prog->progname
, ((trav->rpcreq->prog->procnames) ? trav->rpcreq
->prog->procnames[trav->rpcreq->procnum] : "--"),
trav->rpcreq->procnum, timestr, trav->rpcreq->xid
); } while (0); _gf_log_callingfn (trav->rpcreq->conn->
trans->name, "rpc-clnt.c", __FUNCTION__, 368, GF_LOG_ERROR
, "forced unwinding frame type(%s) op(%s(%d)) " "called at %s (xid=0x%ux)"
, trav->rpcreq->prog->progname, ((trav->rpcreq->
prog->procnames) ? trav->rpcreq->prog->procnames[
trav->rpcreq->procnum] : "--"), trav->rpcreq->procnum
, timestr, trav->rpcreq->xid); } while (0)
365 trav->rpcreq->prog->procnames[trav->rpcreq->procnum]do { do { if (0) printf ("forced unwinding frame type(%s) op(%s(%d)) "
"called at %s (xid=0x%ux)", trav->rpcreq->prog->progname
, ((trav->rpcreq->prog->procnames) ? trav->rpcreq
->prog->procnames[trav->rpcreq->procnum] : "--"),
trav->rpcreq->procnum, timestr, trav->rpcreq->xid
); } while (0); _gf_log_callingfn (trav->rpcreq->conn->
trans->name, "rpc-clnt.c", __FUNCTION__, 368, GF_LOG_ERROR
, "forced unwinding frame type(%s) op(%s(%d)) " "called at %s (xid=0x%ux)"
, trav->rpcreq->prog->progname, ((trav->rpcreq->
prog->procnames) ? trav->rpcreq->prog->procnames[
trav->rpcreq->procnum] : "--"), trav->rpcreq->procnum
, timestr, trav->rpcreq->xid); } while (0)
366 : "--"),do { do { if (0) printf ("forced unwinding frame type(%s) op(%s(%d)) "
"called at %s (xid=0x%ux)", trav->rpcreq->prog->progname
, ((trav->rpcreq->prog->procnames) ? trav->rpcreq
->prog->procnames[trav->rpcreq->procnum] : "--"),
trav->rpcreq->procnum, timestr, trav->rpcreq->xid
); } while (0); _gf_log_callingfn (trav->rpcreq->conn->
trans->name, "rpc-clnt.c", __FUNCTION__, 368, GF_LOG_ERROR
, "forced unwinding frame type(%s) op(%s(%d)) " "called at %s (xid=0x%ux)"
, trav->rpcreq->prog->progname, ((trav->rpcreq->
prog->procnames) ? trav->rpcreq->prog->procnames[
trav->rpcreq->procnum] : "--"), trav->rpcreq->procnum
, timestr, trav->rpcreq->xid); } while (0)
367 trav->rpcreq->procnum, timestr,do { do { if (0) printf ("forced unwinding frame type(%s) op(%s(%d)) "
"called at %s (xid=0x%ux)", trav->rpcreq->prog->progname
, ((trav->rpcreq->prog->procnames) ? trav->rpcreq
->prog->procnames[trav->rpcreq->procnum] : "--"),
trav->rpcreq->procnum, timestr, trav->rpcreq->xid
); } while (0); _gf_log_callingfn (trav->rpcreq->conn->
trans->name, "rpc-clnt.c", __FUNCTION__, 368, GF_LOG_ERROR
, "forced unwinding frame type(%s) op(%s(%d)) " "called at %s (xid=0x%ux)"
, trav->rpcreq->prog->progname, ((trav->rpcreq->
prog->procnames) ? trav->rpcreq->prog->procnames[
trav->rpcreq->procnum] : "--"), trav->rpcreq->procnum
, timestr, trav->rpcreq->xid); } while (0)
368 trav->rpcreq->xid)do { do { if (0) printf ("forced unwinding frame type(%s) op(%s(%d)) "
"called at %s (xid=0x%ux)", trav->rpcreq->prog->progname
, ((trav->rpcreq->prog->procnames) ? trav->rpcreq
->prog->procnames[trav->rpcreq->procnum] : "--"),
trav->rpcreq->procnum, timestr, trav->rpcreq->xid
); } while (0); _gf_log_callingfn (trav->rpcreq->conn->
trans->name, "rpc-clnt.c", __FUNCTION__, 368, GF_LOG_ERROR
, "forced unwinding frame type(%s) op(%s(%d)) " "called at %s (xid=0x%ux)"
, trav->rpcreq->prog->progname, ((trav->rpcreq->
prog->procnames) ? trav->rpcreq->prog->procnames[
trav->rpcreq->procnum] : "--"), trav->rpcreq->procnum
, timestr, trav->rpcreq->xid); } while (0)
;
369 saved_frames->count--;
370
371 trav->rpcreq->rpc_status = -1;
372 trav->rpcreq->cbkfn (trav->rpcreq, &iov, 1, trav->frame);
373
374 rpc_clnt_reply_deinit (trav->rpcreq,
375 trav->rpcreq->conn->rpc_clnt->reqpool);
376
377 list_del_init (&trav->list);
378 mem_put (trav);
379 }
380}
381
382
383void
384saved_frames_destroy (struct saved_frames *frames)
385{
386 if (!frames)
387 return;
388
389 saved_frames_unwind (frames);
390
391 GF_FREE (frames)__gf_free (frames);
392}
393
394
395void
396rpc_clnt_reconnect (void *trans_ptr)
397{
398 rpc_transport_t *trans = NULL((void*)0);
399 rpc_clnt_connection_t *conn = NULL((void*)0);
400 struct timeval tv = {0, 0};
401 int32_t ret = 0;
402 struct rpc_clnt *clnt = NULL((void*)0);
403
404 trans = trans_ptr;
405 if (!trans || !trans->mydata)
406 return;
407
408 conn = trans->mydata;
409 clnt = conn->rpc_clnt;
410
411 pthread_mutex_lock (&conn->lock);
412 {
413 if (conn->reconnect)
414 gf_timer_call_cancel (clnt->ctx,
415 conn->reconnect);
416 conn->reconnect = 0;
417
418 if (conn->connected == 0) {
419 tv.tv_sec = 3;
420
421 gf_log (trans->name, GF_LOG_TRACE,do { do { if (0) printf ("attempting reconnect"); } while (0)
; _gf_log (trans->name, "rpc-clnt.c", __FUNCTION__, 422, GF_LOG_TRACE
, "attempting reconnect"); } while (0)
422 "attempting reconnect")do { do { if (0) printf ("attempting reconnect"); } while (0)
; _gf_log (trans->name, "rpc-clnt.c", __FUNCTION__, 422, GF_LOG_TRACE
, "attempting reconnect"); } while (0)
;
423 ret = rpc_transport_connect (trans,
424 conn->config.remote_port);
425 conn->reconnect =
426 gf_timer_call_after (clnt->ctx, tv,
427 rpc_clnt_reconnect,
428 trans);
429 } else {
430 gf_log (trans->name, GF_LOG_TRACE,do { do { if (0) printf ("breaking reconnect chain"); } while
(0); _gf_log (trans->name, "rpc-clnt.c", __FUNCTION__, 431
, GF_LOG_TRACE, "breaking reconnect chain"); } while (0)
431 "breaking reconnect chain")do { do { if (0) printf ("breaking reconnect chain"); } while
(0); _gf_log (trans->name, "rpc-clnt.c", __FUNCTION__, 431
, GF_LOG_TRACE, "breaking reconnect chain"); } while (0)
;
432 }
433 }
434 pthread_mutex_unlock (&conn->lock);
435
436 if ((ret == -1) && (errno(*__errno_location ()) != EINPROGRESS115) && (clnt->notifyfn)) {
437 clnt->notifyfn (clnt, clnt->mydata, RPC_CLNT_DISCONNECT, NULL((void*)0));
438 }
439
440 return;
441}
442
443
444int
445rpc_clnt_fill_request_info (struct rpc_clnt *clnt, rpc_request_info_t *info)
446{
447 struct saved_frame saved_frame;
448 int ret = -1;
449
450 pthread_mutex_lock (&clnt->conn.lock);
451 {
452 ret = __saved_frame_copy (clnt->conn.saved_frames, info->xid,
453 &saved_frame);
454 }
455 pthread_mutex_unlock (&clnt->conn.lock);
456
457 if (ret == -1) {
458 gf_log (clnt->conn.trans->name, GF_LOG_CRITICAL,do { do { if (0) printf ("cannot lookup the saved " "frame corresponding to xid (%d)"
, info->xid); } while (0); _gf_log (clnt->conn.trans->
name, "rpc-clnt.c", __FUNCTION__, 460, GF_LOG_CRITICAL, "cannot lookup the saved "
"frame corresponding to xid (%d)", info->xid); } while (0
)
459 "cannot lookup the saved "do { do { if (0) printf ("cannot lookup the saved " "frame corresponding to xid (%d)"
, info->xid); } while (0); _gf_log (clnt->conn.trans->
name, "rpc-clnt.c", __FUNCTION__, 460, GF_LOG_CRITICAL, "cannot lookup the saved "
"frame corresponding to xid (%d)", info->xid); } while (0
)
460 "frame corresponding to xid (%d)", info->xid)do { do { if (0) printf ("cannot lookup the saved " "frame corresponding to xid (%d)"
, info->xid); } while (0); _gf_log (clnt->conn.trans->
name, "rpc-clnt.c", __FUNCTION__, 460, GF_LOG_CRITICAL, "cannot lookup the saved "
"frame corresponding to xid (%d)", info->xid); } while (0
)
;
461 goto out;
462 }
463
464 info->prognum = saved_frame.rpcreq->prog->prognum;
465 info->procnum = saved_frame.rpcreq->procnum;
466 info->progver = saved_frame.rpcreq->prog->progver;
467 info->rpc_req = saved_frame.rpcreq;
468 info->rsp = saved_frame.rsp;
469
470 ret = 0;
471out:
472 return ret;
473}
474
475int
476rpc_clnt_reconnect_cleanup (rpc_clnt_connection_t *conn)
477{
478 struct rpc_clnt *clnt = NULL((void*)0);
479
480 if (!conn) {
481 goto out;
482 }
483
484 clnt = conn->rpc_clnt;
485
486 pthread_mutex_lock (&conn->lock);
487 {
488
489 if (conn->reconnect) {
490 gf_timer_call_cancel (clnt->ctx, conn->reconnect);
491 conn->reconnect = NULL((void*)0);
492 }
493
494 }
495 pthread_mutex_unlock (&conn->lock);
496
497out:
498 return 0;
499}
500
501/*
502 * client_protocol_cleanup - cleanup function
503 * @trans: transport object
504 *
505 */
506int
507rpc_clnt_connection_cleanup (rpc_clnt_connection_t *conn)
508{
509 struct saved_frames *saved_frames = NULL((void*)0);
510 struct rpc_clnt *clnt = NULL((void*)0);
511
512 if (!conn) {
513 goto out;
514 }
515
516 clnt = conn->rpc_clnt;
517
518 gf_log (conn->trans->name, GF_LOG_TRACE,do { do { if (0) printf ("cleaning up state in transport object %p"
, conn->trans); } while (0); _gf_log (conn->trans->name
, "rpc-clnt.c", __FUNCTION__, 519, GF_LOG_TRACE, "cleaning up state in transport object %p"
, conn->trans); } while (0)
519 "cleaning up state in transport object %p", conn->trans)do { do { if (0) printf ("cleaning up state in transport object %p"
, conn->trans); } while (0); _gf_log (conn->trans->name
, "rpc-clnt.c", __FUNCTION__, 519, GF_LOG_TRACE, "cleaning up state in transport object %p"
, conn->trans); } while (0)
;
520
521 pthread_mutex_lock (&conn->lock);
522 {
523 saved_frames = conn->saved_frames;
524 conn->saved_frames = saved_frames_new ();
525
526 /* bailout logic cleanup */
527 if (conn->timer) {
528 gf_timer_call_cancel (clnt->ctx, conn->timer);
529 conn->timer = NULL((void*)0);
530 }
531
532 conn->connected = 0;
533
534 if (conn->ping_timer) {
535 gf_timer_call_cancel (clnt->ctx, conn->ping_timer);
536 conn->ping_timer = NULL((void*)0);
537 conn->ping_started = 0;
538 }
539 }
540 pthread_mutex_unlock (&conn->lock);
541
542 saved_frames_destroy (saved_frames);
543
544out:
545 return 0;
546}
547
548/*
549 * lookup_frame - lookup call frame corresponding to a given callid
550 * @trans: transport object
551 * @callid: call id of the frame
552 *
553 * not for external reference
554 */
555
556static struct saved_frame *
557lookup_frame (rpc_clnt_connection_t *conn, int64_t callid)
558{
559 struct saved_frame *frame = NULL((void*)0);
560
561 pthread_mutex_lock (&conn->lock);
562 {
563 frame = __saved_frame_get (conn->saved_frames, callid);
564 }
565 pthread_mutex_unlock (&conn->lock);
566
567 return frame;
568}
569
570
571int
572rpc_clnt_reply_fill (rpc_transport_pollin_t *msg,
573 rpc_clnt_connection_t *conn,
574 struct rpc_msg *replymsg, struct iovec progmsg,
575 struct rpc_req *req,
576 struct saved_frame *saved_frame)
577{
578 int ret = -1;
579
580 if ((!conn) || (!replymsg)|| (!req) || (!saved_frame) || (!msg)) {
581 goto out;
582 }
583
584 req->rpc_status = 0;
585 if ((rpc_reply_status (replymsg)((replymsg)->ru.RM_rmb.rp_stat) == MSG_DENIED)
586 || (rpc_accepted_reply_status (replymsg)((replymsg)->ru.RM_rmb.ru.RP_ar.ar_stat) != SUCCESS)) {
587 req->rpc_status = -1;
588 }
589
590 req->rsp[0] = progmsg;
591 req->rsp_iobref = iobref_ref (msg->iobref);
592
593 if (msg->vectored) {
594 req->rsp[1] = msg->vector[1];
595 req->rspcnt = 2;
596 } else {
597 req->rspcnt = 1;
598 }
599
600 /* By this time, the data bytes for the auth scheme would have already
601 * been copied into the required sections of the req structure,
602 * we just need to fill in the meta-data about it now.
603 */
604 if (req->rpc_status == 0) {
605 /*
606 * req->verf.flavour = rpc_reply_verf_flavour (replymsg);
607 * req->verf.datalen = rpc_reply_verf_len (replymsg);
608 */
609 }
610
611 ret = 0;
612
613out:
614 return ret;
615}
616
617
618void
619rpc_clnt_reply_deinit (struct rpc_req *req, struct mem_pool *pool)
620{
621 if (!req) {
622 goto out;
623 }
624
625 if (req->rsp_iobref) {
626 iobref_unref (req->rsp_iobref);
627 }
628
629 mem_put (req);
630out:
631 return;
632}
633
634
635/* TODO: use mem-pool for allocating requests */
636int
637rpc_clnt_reply_init (rpc_clnt_connection_t *conn, rpc_transport_pollin_t *msg,
638 struct rpc_req *req, struct saved_frame *saved_frame)
639{
640 char *msgbuf = NULL((void*)0);
641 struct rpc_msg rpcmsg;
642 struct iovec progmsg; /* RPC Program payload */
643 size_t msglen = 0;
644 int ret = -1;
645
646 msgbuf = msg->vector[0].iov_base;
647 msglen = msg->vector[0].iov_len;
648
649 ret = xdr_to_rpc_reply (msgbuf, msglen, &rpcmsg, &progmsg,
650 req->verf.authdata);
651 if (ret != 0) {
652 gf_log (conn->trans->name, GF_LOG_WARNING,do { do { if (0) printf ("RPC reply decoding failed"); } while
(0); _gf_log (conn->trans->name, "rpc-clnt.c", __FUNCTION__
, 653, GF_LOG_WARNING, "RPC reply decoding failed"); } while (
0)
653 "RPC reply decoding failed")do { do { if (0) printf ("RPC reply decoding failed"); } while
(0); _gf_log (conn->trans->name, "rpc-clnt.c", __FUNCTION__
, 653, GF_LOG_WARNING, "RPC reply decoding failed"); } while (
0)
;
654 goto out;
655 }
656
657 ret = rpc_clnt_reply_fill (msg, conn, &rpcmsg, progmsg, req,
658 saved_frame);
659 if (ret != 0) {
660 goto out;
661 }
662
663 gf_log (conn->trans->name, GF_LOG_TRACE,do { do { if (0) printf ("received rpc message (RPC XID: 0x%ux"
" Program: %s, ProgVers: %d, Proc: %d) from rpc-transport (%s)"
, saved_frame->rpcreq->xid, saved_frame->rpcreq->
prog->progname, saved_frame->rpcreq->prog->progver
, saved_frame->rpcreq->procnum, conn->trans->name
); } while (0); _gf_log (conn->trans->name, "rpc-clnt.c"
, __FUNCTION__, 669, GF_LOG_TRACE, "received rpc message (RPC XID: 0x%ux"
" Program: %s, ProgVers: %d, Proc: %d) from rpc-transport (%s)"
, saved_frame->rpcreq->xid, saved_frame->rpcreq->
prog->progname, saved_frame->rpcreq->prog->progver
, saved_frame->rpcreq->procnum, conn->trans->name
); } while (0)
664 "received rpc message (RPC XID: 0x%ux"do { do { if (0) printf ("received rpc message (RPC XID: 0x%ux"
" Program: %s, ProgVers: %d, Proc: %d) from rpc-transport (%s)"
, saved_frame->rpcreq->xid, saved_frame->rpcreq->
prog->progname, saved_frame->rpcreq->prog->progver
, saved_frame->rpcreq->procnum, conn->trans->name
); } while (0); _gf_log (conn->trans->name, "rpc-clnt.c"
, __FUNCTION__, 669, GF_LOG_TRACE, "received rpc message (RPC XID: 0x%ux"
" Program: %s, ProgVers: %d, Proc: %d) from rpc-transport (%s)"
, saved_frame->rpcreq->xid, saved_frame->rpcreq->
prog->progname, saved_frame->rpcreq->prog->progver
, saved_frame->rpcreq->procnum, conn->trans->name
); } while (0)
665 " Program: %s, ProgVers: %d, Proc: %d) from rpc-transport (%s)",do { do { if (0) printf ("received rpc message (RPC XID: 0x%ux"
" Program: %s, ProgVers: %d, Proc: %d) from rpc-transport (%s)"
, saved_frame->rpcreq->xid, saved_frame->rpcreq->
prog->progname, saved_frame->rpcreq->prog->progver
, saved_frame->rpcreq->procnum, conn->trans->name
); } while (0); _gf_log (conn->trans->name, "rpc-clnt.c"
, __FUNCTION__, 669, GF_LOG_TRACE, "received rpc message (RPC XID: 0x%ux"
" Program: %s, ProgVers: %d, Proc: %d) from rpc-transport (%s)"
, saved_frame->rpcreq->xid, saved_frame->rpcreq->
prog->progname, saved_frame->rpcreq->prog->progver
, saved_frame->rpcreq->procnum, conn->trans->name
); } while (0)
666 saved_frame->rpcreq->xid,do { do { if (0) printf ("received rpc message (RPC XID: 0x%ux"
" Program: %s, ProgVers: %d, Proc: %d) from rpc-transport (%s)"
, saved_frame->rpcreq->xid, saved_frame->rpcreq->
prog->progname, saved_frame->rpcreq->prog->progver
, saved_frame->rpcreq->procnum, conn->trans->name
); } while (0); _gf_log (conn->trans->name, "rpc-clnt.c"
, __FUNCTION__, 669, GF_LOG_TRACE, "received rpc message (RPC XID: 0x%ux"
" Program: %s, ProgVers: %d, Proc: %d) from rpc-transport (%s)"
, saved_frame->rpcreq->xid, saved_frame->rpcreq->
prog->progname, saved_frame->rpcreq->prog->progver
, saved_frame->rpcreq->procnum, conn->trans->name
); } while (0)
667 saved_frame->rpcreq->prog->progname,do { do { if (0) printf ("received rpc message (RPC XID: 0x%ux"
" Program: %s, ProgVers: %d, Proc: %d) from rpc-transport (%s)"
, saved_frame->rpcreq->xid, saved_frame->rpcreq->
prog->progname, saved_frame->rpcreq->prog->progver
, saved_frame->rpcreq->procnum, conn->trans->name
); } while (0); _gf_log (conn->trans->name, "rpc-clnt.c"
, __FUNCTION__, 669, GF_LOG_TRACE, "received rpc message (RPC XID: 0x%ux"
" Program: %s, ProgVers: %d, Proc: %d) from rpc-transport (%s)"
, saved_frame->rpcreq->xid, saved_frame->rpcreq->
prog->progname, saved_frame->rpcreq->prog->progver
, saved_frame->rpcreq->procnum, conn->trans->name
); } while (0)
668 saved_frame->rpcreq->prog->progver,do { do { if (0) printf ("received rpc message (RPC XID: 0x%ux"
" Program: %s, ProgVers: %d, Proc: %d) from rpc-transport (%s)"
, saved_frame->rpcreq->xid, saved_frame->rpcreq->
prog->progname, saved_frame->rpcreq->prog->progver
, saved_frame->rpcreq->procnum, conn->trans->name
); } while (0); _gf_log (conn->trans->name, "rpc-clnt.c"
, __FUNCTION__, 669, GF_LOG_TRACE, "received rpc message (RPC XID: 0x%ux"
" Program: %s, ProgVers: %d, Proc: %d) from rpc-transport (%s)"
, saved_frame->rpcreq->xid, saved_frame->rpcreq->
prog->progname, saved_frame->rpcreq->prog->progver
, saved_frame->rpcreq->procnum, conn->trans->name
); } while (0)
669 saved_frame->rpcreq->procnum, conn->trans->name)do { do { if (0) printf ("received rpc message (RPC XID: 0x%ux"
" Program: %s, ProgVers: %d, Proc: %d) from rpc-transport (%s)"
, saved_frame->rpcreq->xid, saved_frame->rpcreq->
prog->progname, saved_frame->rpcreq->prog->progver
, saved_frame->rpcreq->procnum, conn->trans->name
); } while (0); _gf_log (conn->trans->name, "rpc-clnt.c"
, __FUNCTION__, 669, GF_LOG_TRACE, "received rpc message (RPC XID: 0x%ux"
" Program: %s, ProgVers: %d, Proc: %d) from rpc-transport (%s)"
, saved_frame->rpcreq->xid, saved_frame->rpcreq->
prog->progname, saved_frame->rpcreq->prog->progver
, saved_frame->rpcreq->procnum, conn->trans->name
); } while (0)
;
670
671out:
672 if (ret != 0) {
673 req->rpc_status = -1;
674 }
675
676 return ret;
677}
678
679int
680rpc_clnt_handle_cbk (struct rpc_clnt *clnt, rpc_transport_pollin_t *msg)
681{
682 char *msgbuf = NULL((void*)0);
683 rpcclnt_cb_program_t *program = NULL((void*)0);
684 struct rpc_msg rpcmsg;
685 struct iovec progmsg; /* RPC Program payload */
686 size_t msglen = 0;
687 int found = 0;
688 int ret = -1;
689 int procnum = 0;
690
691 msgbuf = msg->vector[0].iov_base;
692 msglen = msg->vector[0].iov_len;
693
694 clnt = rpc_clnt_ref (clnt);
695 ret = xdr_to_rpc_call (msgbuf, msglen, &rpcmsg, &progmsg, NULL((void*)0),NULL((void*)0));
696 if (ret == -1) {
697 gf_log (clnt->conn.trans->name, GF_LOG_WARNING,do { do { if (0) printf ("RPC call decoding failed"); } while
(0); _gf_log (clnt->conn.trans->name, "rpc-clnt.c", __FUNCTION__
, 698, GF_LOG_WARNING, "RPC call decoding failed"); } while (
0)
698 "RPC call decoding failed")do { do { if (0) printf ("RPC call decoding failed"); } while
(0); _gf_log (clnt->conn.trans->name, "rpc-clnt.c", __FUNCTION__
, 698, GF_LOG_WARNING, "RPC call decoding failed"); } while (
0)
;
699 goto out;
700 }
701
702 gf_log (clnt->conn.trans->name, GF_LOG_TRACE,do { do { if (0) printf ("received rpc message (XID: 0x%lx, "
"Ver: %ld, Program: %ld, ProgVers: %ld, Proc: %ld) " "from rpc-transport (%s)"
, ((&rpcmsg)->rm_xid), ((&rpcmsg)->ru.RM_cmb.cb_rpcvers
), ((&rpcmsg)->ru.RM_cmb.cb_prog), ((&rpcmsg)->
ru.RM_cmb.cb_vers), ((&rpcmsg)->ru.RM_cmb.cb_proc), clnt
->conn.trans->name); } while (0); _gf_log (clnt->conn
.trans->name, "rpc-clnt.c", __FUNCTION__, 708, GF_LOG_TRACE
, "received rpc message (XID: 0x%lx, " "Ver: %ld, Program: %ld, ProgVers: %ld, Proc: %ld) "
"from rpc-transport (%s)", ((&rpcmsg)->rm_xid), ((&
rpcmsg)->ru.RM_cmb.cb_rpcvers), ((&rpcmsg)->ru.RM_cmb
.cb_prog), ((&rpcmsg)->ru.RM_cmb.cb_vers), ((&rpcmsg
)->ru.RM_cmb.cb_proc), clnt->conn.trans->name); } while
(0)
703 "received rpc message (XID: 0x%lx, "do { do { if (0) printf ("received rpc message (XID: 0x%lx, "
"Ver: %ld, Program: %ld, ProgVers: %ld, Proc: %ld) " "from rpc-transport (%s)"
, ((&rpcmsg)->rm_xid), ((&rpcmsg)->ru.RM_cmb.cb_rpcvers
), ((&rpcmsg)->ru.RM_cmb.cb_prog), ((&rpcmsg)->
ru.RM_cmb.cb_vers), ((&rpcmsg)->ru.RM_cmb.cb_proc), clnt
->conn.trans->name); } while (0); _gf_log (clnt->conn
.trans->name, "rpc-clnt.c", __FUNCTION__, 708, GF_LOG_TRACE
, "received rpc message (XID: 0x%lx, " "Ver: %ld, Program: %ld, ProgVers: %ld, Proc: %ld) "
"from rpc-transport (%s)", ((&rpcmsg)->rm_xid), ((&
rpcmsg)->ru.RM_cmb.cb_rpcvers), ((&rpcmsg)->ru.RM_cmb
.cb_prog), ((&rpcmsg)->ru.RM_cmb.cb_vers), ((&rpcmsg
)->ru.RM_cmb.cb_proc), clnt->conn.trans->name); } while
(0)
704 "Ver: %ld, Program: %ld, ProgVers: %ld, Proc: %ld) "do { do { if (0) printf ("received rpc message (XID: 0x%lx, "
"Ver: %ld, Program: %ld, ProgVers: %ld, Proc: %ld) " "from rpc-transport (%s)"
, ((&rpcmsg)->rm_xid), ((&rpcmsg)->ru.RM_cmb.cb_rpcvers
), ((&rpcmsg)->ru.RM_cmb.cb_prog), ((&rpcmsg)->
ru.RM_cmb.cb_vers), ((&rpcmsg)->ru.RM_cmb.cb_proc), clnt
->conn.trans->name); } while (0); _gf_log (clnt->conn
.trans->name, "rpc-clnt.c", __FUNCTION__, 708, GF_LOG_TRACE
, "received rpc message (XID: 0x%lx, " "Ver: %ld, Program: %ld, ProgVers: %ld, Proc: %ld) "
"from rpc-transport (%s)", ((&rpcmsg)->rm_xid), ((&
rpcmsg)->ru.RM_cmb.cb_rpcvers), ((&rpcmsg)->ru.RM_cmb
.cb_prog), ((&rpcmsg)->ru.RM_cmb.cb_vers), ((&rpcmsg
)->ru.RM_cmb.cb_proc), clnt->conn.trans->name); } while
(0)
705 "from rpc-transport (%s)", rpc_call_xid (&rpcmsg),do { do { if (0) printf ("received rpc message (XID: 0x%lx, "
"Ver: %ld, Program: %ld, ProgVers: %ld, Proc: %ld) " "from rpc-transport (%s)"
, ((&rpcmsg)->rm_xid), ((&rpcmsg)->ru.RM_cmb.cb_rpcvers
), ((&rpcmsg)->ru.RM_cmb.cb_prog), ((&rpcmsg)->
ru.RM_cmb.cb_vers), ((&rpcmsg)->ru.RM_cmb.cb_proc), clnt
->conn.trans->name); } while (0); _gf_log (clnt->conn
.trans->name, "rpc-clnt.c", __FUNCTION__, 708, GF_LOG_TRACE
, "received rpc message (XID: 0x%lx, " "Ver: %ld, Program: %ld, ProgVers: %ld, Proc: %ld) "
"from rpc-transport (%s)", ((&rpcmsg)->rm_xid), ((&
rpcmsg)->ru.RM_cmb.cb_rpcvers), ((&rpcmsg)->ru.RM_cmb
.cb_prog), ((&rpcmsg)->ru.RM_cmb.cb_vers), ((&rpcmsg
)->ru.RM_cmb.cb_proc), clnt->conn.trans->name); } while
(0)
706 rpc_call_rpcvers (&rpcmsg), rpc_call_program (&rpcmsg),do { do { if (0) printf ("received rpc message (XID: 0x%lx, "
"Ver: %ld, Program: %ld, ProgVers: %ld, Proc: %ld) " "from rpc-transport (%s)"
, ((&rpcmsg)->rm_xid), ((&rpcmsg)->ru.RM_cmb.cb_rpcvers
), ((&rpcmsg)->ru.RM_cmb.cb_prog), ((&rpcmsg)->
ru.RM_cmb.cb_vers), ((&rpcmsg)->ru.RM_cmb.cb_proc), clnt
->conn.trans->name); } while (0); _gf_log (clnt->conn
.trans->name, "rpc-clnt.c", __FUNCTION__, 708, GF_LOG_TRACE
, "received rpc message (XID: 0x%lx, " "Ver: %ld, Program: %ld, ProgVers: %ld, Proc: %ld) "
"from rpc-transport (%s)", ((&rpcmsg)->rm_xid), ((&
rpcmsg)->ru.RM_cmb.cb_rpcvers), ((&rpcmsg)->ru.RM_cmb
.cb_prog), ((&rpcmsg)->ru.RM_cmb.cb_vers), ((&rpcmsg
)->ru.RM_cmb.cb_proc), clnt->conn.trans->name); } while
(0)
707 rpc_call_progver (&rpcmsg), rpc_call_progproc (&rpcmsg),do { do { if (0) printf ("received rpc message (XID: 0x%lx, "
"Ver: %ld, Program: %ld, ProgVers: %ld, Proc: %ld) " "from rpc-transport (%s)"
, ((&rpcmsg)->rm_xid), ((&rpcmsg)->ru.RM_cmb.cb_rpcvers
), ((&rpcmsg)->ru.RM_cmb.cb_prog), ((&rpcmsg)->
ru.RM_cmb.cb_vers), ((&rpcmsg)->ru.RM_cmb.cb_proc), clnt
->conn.trans->name); } while (0); _gf_log (clnt->conn
.trans->name, "rpc-clnt.c", __FUNCTION__, 708, GF_LOG_TRACE
, "received rpc message (XID: 0x%lx, " "Ver: %ld, Program: %ld, ProgVers: %ld, Proc: %ld) "
"from rpc-transport (%s)", ((&rpcmsg)->rm_xid), ((&
rpcmsg)->ru.RM_cmb.cb_rpcvers), ((&rpcmsg)->ru.RM_cmb
.cb_prog), ((&rpcmsg)->ru.RM_cmb.cb_vers), ((&rpcmsg
)->ru.RM_cmb.cb_proc), clnt->conn.trans->name); } while
(0)
708 clnt->conn.trans->name)do { do { if (0) printf ("received rpc message (XID: 0x%lx, "
"Ver: %ld, Program: %ld, ProgVers: %ld, Proc: %ld) " "from rpc-transport (%s)"
, ((&rpcmsg)->rm_xid), ((&rpcmsg)->ru.RM_cmb.cb_rpcvers
), ((&rpcmsg)->ru.RM_cmb.cb_prog), ((&rpcmsg)->
ru.RM_cmb.cb_vers), ((&rpcmsg)->ru.RM_cmb.cb_proc), clnt
->conn.trans->name); } while (0); _gf_log (clnt->conn
.trans->name, "rpc-clnt.c", __FUNCTION__, 708, GF_LOG_TRACE
, "received rpc message (XID: 0x%lx, " "Ver: %ld, Program: %ld, ProgVers: %ld, Proc: %ld) "
"from rpc-transport (%s)", ((&rpcmsg)->rm_xid), ((&
rpcmsg)->ru.RM_cmb.cb_rpcvers), ((&rpcmsg)->ru.RM_cmb
.cb_prog), ((&rpcmsg)->ru.RM_cmb.cb_vers), ((&rpcmsg
)->ru.RM_cmb.cb_proc), clnt->conn.trans->name); } while
(0)
;
709
710 procnum = rpc_call_progproc (&rpcmsg)((&rpcmsg)->ru.RM_cmb.cb_proc);
711
712 pthread_mutex_lock (&clnt->lock);
713 {
714 list_for_each_entry (program, &clnt->programs, program)for (program = ((typeof(*program) *)((char *)((&clnt->
programs)->next)-(unsigned long)(&((typeof(*program) *
)0)->program))); &program->program != (&clnt->
programs); program = ((typeof(*program) *)((char *)(program->
program.next)-(unsigned long)(&((typeof(*program) *)0)->
program))))
{
715 if ((program->prognum == rpc_call_program (&rpcmsg)((&rpcmsg)->ru.RM_cmb.cb_prog))
716 && (program->progver
717 == rpc_call_progver (&rpcmsg)((&rpcmsg)->ru.RM_cmb.cb_vers))) {
718 found = 1;
719 break;
720 }
721 }
722 }
723 pthread_mutex_unlock (&clnt->lock);
724
725 if (found && (procnum < program->numactors) &&
726 (program->actors[procnum].actor)) {
727 program->actors[procnum].actor (clnt, program->mydata,
728 &progmsg);
729 }
730
731out:
732 clnt = rpc_clnt_unref (clnt);
733 return ret;
734}
735
736int
737rpc_clnt_handle_reply (struct rpc_clnt *clnt, rpc_transport_pollin_t *pollin)
738{
739 rpc_clnt_connection_t *conn = NULL((void*)0);
740 struct saved_frame *saved_frame = NULL((void*)0);
741 int ret = -1;
742 struct rpc_req *req = NULL((void*)0);
743 uint32_t xid = 0;
744
745 clnt = rpc_clnt_ref (clnt);
746 conn = &clnt->conn;
747
748 xid = ntoh32hton32 (*((uint32_t *)pollin->vector[0].iov_base));
749 saved_frame = lookup_frame (conn, xid);
750 if (saved_frame == NULL((void*)0)) {
751 gf_log (conn->trans->name, GF_LOG_ERROR,do { do { if (0) printf ("cannot lookup the saved frame for reply with xid (%u)"
, xid); } while (0); _gf_log (conn->trans->name, "rpc-clnt.c"
, __FUNCTION__, 753, GF_LOG_ERROR, "cannot lookup the saved frame for reply with xid (%u)"
, xid); } while (0)
752 "cannot lookup the saved frame for reply with xid (%u)",do { do { if (0) printf ("cannot lookup the saved frame for reply with xid (%u)"
, xid); } while (0); _gf_log (conn->trans->name, "rpc-clnt.c"
, __FUNCTION__, 753, GF_LOG_ERROR, "cannot lookup the saved frame for reply with xid (%u)"
, xid); } while (0)
753 xid)do { do { if (0) printf ("cannot lookup the saved frame for reply with xid (%u)"
, xid); } while (0); _gf_log (conn->trans->name, "rpc-clnt.c"
, __FUNCTION__, 753, GF_LOG_ERROR, "cannot lookup the saved frame for reply with xid (%u)"
, xid); } while (0)
;
754 goto out;
755 }
756
757 req = saved_frame->rpcreq;
758 if (req == NULL((void*)0)) {
759 gf_log (conn->trans->name, GF_LOG_ERROR,do { do { if (0) printf ("no request with frame for xid (%u)"
, xid); } while (0); _gf_log (conn->trans->name, "rpc-clnt.c"
, __FUNCTION__, 760, GF_LOG_ERROR, "no request with frame for xid (%u)"
, xid); } while (0)
760 "no request with frame for xid (%u)", xid)do { do { if (0) printf ("no request with frame for xid (%u)"
, xid); } while (0); _gf_log (conn->trans->name, "rpc-clnt.c"
, __FUNCTION__, 760, GF_LOG_ERROR, "no request with frame for xid (%u)"
, xid); } while (0)
;
761 goto out;
762 }
763
764 ret = rpc_clnt_reply_init (conn, pollin, req, saved_frame);
765 if (ret != 0) {
766 req->rpc_status = -1;
767 gf_log (conn->trans->name, GF_LOG_WARNING,do { do { if (0) printf ("initialising rpc reply failed"); } while
(0); _gf_log (conn->trans->name, "rpc-clnt.c", __FUNCTION__
, 768, GF_LOG_WARNING, "initialising rpc reply failed"); } while
(0)
768 "initialising rpc reply failed")do { do { if (0) printf ("initialising rpc reply failed"); } while
(0); _gf_log (conn->trans->name, "rpc-clnt.c", __FUNCTION__
, 768, GF_LOG_WARNING, "initialising rpc reply failed"); } while
(0)
;
769 }
770
771 req->cbkfn (req, req->rsp, req->rspcnt, saved_frame->frame);
772
773 if (req) {
774 rpc_clnt_reply_deinit (req, conn->rpc_clnt->reqpool);
775 }
776out:
777
778 if (saved_frame) {
779 mem_put (saved_frame);
780 }
781
782 clnt = rpc_clnt_unref (clnt);
783 return ret;
784}
785
786
787inline void
788rpc_clnt_set_connected (rpc_clnt_connection_t *conn)
789{
790 if (!conn) {
791 goto out;
792 }
793
794 pthread_mutex_lock (&conn->lock);
795 {
796 conn->connected = 1;
797 }
798 pthread_mutex_unlock (&conn->lock);
799
800out:
801 return;
802}
803
804
805void
806rpc_clnt_unset_connected (rpc_clnt_connection_t *conn)
807{
808 if (!conn) {
809 goto out;
810 }
811
812 pthread_mutex_lock (&conn->lock);
813 {
814 conn->connected = 0;
815 }
816 pthread_mutex_unlock (&conn->lock);
817
818out:
819 return;
820}
821
822int
823rpc_clnt_notify (rpc_transport_t *trans, void *mydata,
824 rpc_transport_event_t event, void *data, ...)
825{
826 rpc_clnt_connection_t *conn = NULL((void*)0);
827 struct rpc_clnt *clnt = NULL((void*)0);
828 int ret = -1;
829 rpc_request_info_t *req_info = NULL((void*)0);
830 rpc_transport_pollin_t *pollin = NULL((void*)0);
831 struct timeval tv = {0, };
832
833 conn = mydata;
834 if (conn == NULL((void*)0)) {
835 goto out;
836 }
837 clnt = conn->rpc_clnt;
838 if (!clnt)
839 goto out;
840
841 switch (event) {
842 case RPC_TRANSPORT_DISCONNECT:
843 {
844 rpc_clnt_connection_cleanup (conn);
845
846 pthread_mutex_lock (&conn->lock);
847 {
848 if (!conn->rpc_clnt->disabled
849 && (conn->reconnect == NULL((void*)0))) {
850 tv.tv_sec = 10;
851
852 conn->reconnect =
853 gf_timer_call_after (clnt->ctx, tv,
854 rpc_clnt_reconnect,
855 conn->trans);
856 }
857 }
858 pthread_mutex_unlock (&conn->lock);
859
860 if (clnt->notifyfn)
861 ret = clnt->notifyfn (clnt, clnt->mydata,
862 RPC_CLNT_DISCONNECT, NULL((void*)0));
863 break;
864 }
865
866 case RPC_TRANSPORT_CLEANUP:
867 /* this event should not be received on a client for, a
868 * transport is only disconnected, but never destroyed.
869 */
870 ret = 0;
871 break;
872
873 case RPC_TRANSPORT_MAP_XID_REQUEST:
874 {
875 req_info = data;
876 ret = rpc_clnt_fill_request_info (clnt, req_info);
877 break;
878 }
879
880 case RPC_TRANSPORT_MSG_RECEIVED:
881 {
882 pthread_mutex_lock (&conn->lock);
883 {
884 gettimeofday (&conn->last_received, NULL((void*)0));
885 }
886 pthread_mutex_unlock (&conn->lock);
887
888 pollin = data;
889 if (pollin->is_reply)
890 ret = rpc_clnt_handle_reply (clnt, pollin);
891 else
892 ret = rpc_clnt_handle_cbk (clnt, pollin);
893 /* ret = clnt->notifyfn (clnt, clnt->mydata, RPC_CLNT_MSG,
894 * data);
895 */
896 break;
897 }
898
899 case RPC_TRANSPORT_MSG_SENT:
900 {
901 pthread_mutex_lock (&conn->lock);
902 {
903 gettimeofday (&conn->last_sent, NULL((void*)0));
904 }
905 pthread_mutex_unlock (&conn->lock);
906
907 ret = 0;
908 break;
909 }
910
911 case RPC_TRANSPORT_CONNECT:
912 {
913 /* Every time there is a disconnection, processes
914 should try to connect to 'glusterd' (ie, default
915 port) or whichever port given as 'option remote-port'
916 in volume file. */
917 /* Below code makes sure the (re-)configured port lasts
918 for just one successful attempt */
919 conn->config.remote_port = 0;
920
921 if (clnt->notifyfn)
922 ret = clnt->notifyfn (clnt, clnt->mydata,
923 RPC_CLNT_CONNECT, NULL((void*)0));
924 break;
925 }
926
927 case RPC_TRANSPORT_ACCEPT:
928 /* only meaningful on a server, no need of handling this event
929 * in a client.
930 */
931 ret = 0;
932 break;
933 }
934
935out:
936 return ret;
937}
938
939
940void
941rpc_clnt_connection_deinit (rpc_clnt_connection_t *conn)
942{
943 return;
944}
945
946
947static inline int
948rpc_clnt_connection_init (struct rpc_clnt *clnt, glusterfs_ctx_t *ctx,
949 dict_t *options, char *name)
950{
951 int ret = -1;
952 rpc_clnt_connection_t *conn = NULL((void*)0);
953
954 conn = &clnt->conn;
955 pthread_mutex_init (&clnt->conn.lock, NULL((void*)0));
956
957 ret = dict_get_int32 (options, "frame-timeout",
958 &conn->frame_timeout);
959 if (ret >= 0) {
960 gf_log (name, GF_LOG_INFO,do { do { if (0) printf ("setting frame-timeout to %d", conn->
frame_timeout); } while (0); _gf_log (name, "rpc-clnt.c", __FUNCTION__
, 961, GF_LOG_INFO, "setting frame-timeout to %d", conn->frame_timeout
); } while (0)
961 "setting frame-timeout to %d", conn->frame_timeout)do { do { if (0) printf ("setting frame-timeout to %d", conn->
frame_timeout); } while (0); _gf_log (name, "rpc-clnt.c", __FUNCTION__
, 961, GF_LOG_INFO, "setting frame-timeout to %d", conn->frame_timeout
); } while (0)
;
962 } else {
963 gf_log (name, GF_LOG_DEBUG,do { do { if (0) printf ("defaulting frame-timeout to 30mins"
); } while (0); _gf_log (name, "rpc-clnt.c", __FUNCTION__, 964
, GF_LOG_DEBUG, "defaulting frame-timeout to 30mins"); } while
(0)
964 "defaulting frame-timeout to 30mins")do { do { if (0) printf ("defaulting frame-timeout to 30mins"
); } while (0); _gf_log (name, "rpc-clnt.c", __FUNCTION__, 964
, GF_LOG_DEBUG, "defaulting frame-timeout to 30mins"); } while
(0)
;
965 conn->frame_timeout = 1800;
966 }
967
968 conn->trans = rpc_transport_load (ctx, options, name);
969 if (!conn->trans) {
970 gf_log (name, GF_LOG_WARNING, "loading of new rpc-transport"do { do { if (0) printf ("loading of new rpc-transport" " failed"
); } while (0); _gf_log (name, "rpc-clnt.c", __FUNCTION__, 971
, GF_LOG_WARNING, "loading of new rpc-transport" " failed"); }
while (0)
971 " failed")do { do { if (0) printf ("loading of new rpc-transport" " failed"
); } while (0); _gf_log (name, "rpc-clnt.c", __FUNCTION__, 971
, GF_LOG_WARNING, "loading of new rpc-transport" " failed"); }
while (0)
;
972 ret = -1;
973 goto out;
974 }
975
976 rpc_transport_ref (conn->trans);
977
978 conn->rpc_clnt = clnt;
979
980 ret = rpc_transport_register_notify (conn->trans, rpc_clnt_notify,
981 conn);
982 if (ret == -1) {
983 gf_log (name, GF_LOG_WARNING, "registering notify failed")do { do { if (0) printf ("registering notify failed"); } while
(0); _gf_log (name, "rpc-clnt.c", __FUNCTION__, 983, GF_LOG_WARNING
, "registering notify failed"); } while (0)
;
984 rpc_clnt_connection_cleanup (conn);
985 conn = NULL((void*)0);
986 goto out;
987 }
988
989 conn->saved_frames = saved_frames_new ();
990 if (!conn->saved_frames) {
991 gf_log (name, GF_LOG_WARNING, "creation of saved_frames "do { do { if (0) printf ("creation of saved_frames " "failed"
); } while (0); _gf_log (name, "rpc-clnt.c", __FUNCTION__, 992
, GF_LOG_WARNING, "creation of saved_frames " "failed"); } while
(0)
992 "failed")do { do { if (0) printf ("creation of saved_frames " "failed"
); } while (0); _gf_log (name, "rpc-clnt.c", __FUNCTION__, 992
, GF_LOG_WARNING, "creation of saved_frames " "failed"); } while
(0)
;
993 rpc_clnt_connection_cleanup (conn);
994 goto out;
995 }
996
997 ret = 0;
998
999out:
1000 return ret;
1001}
1002
1003struct rpc_clnt *
1004rpc_clnt_new (dict_t *options, glusterfs_ctx_t *ctx, char *name,
1005 uint32_t reqpool_size)
1006{
1007 int ret = -1;
1008 struct rpc_clnt *rpc = NULL((void*)0);
1009
1010 rpc = GF_CALLOC (1, sizeof (*rpc), gf_common_mt_rpcclnt_t)__gf_calloc (1, sizeof (*rpc), gf_common_mt_rpcclnt_t);
1011 if (!rpc) {
1012 goto out;
1013 }
1014
1015 pthread_mutex_init (&rpc->lock, NULL((void*)0));
1016 rpc->ctx = ctx;
1017
1018 if (!reqpool_size)
1019 reqpool_size = RPC_CLNT_DEFAULT_REQUEST_COUNT512;
1020
1021 rpc->reqpool = mem_pool_new (struct rpc_req, reqpool_size)mem_pool_new_fn (sizeof(struct rpc_req), reqpool_size, "struct rpc_req"
)
;
1022 if (rpc->reqpool == NULL((void*)0)) {
1023 pthread_mutex_destroy (&rpc->lock);
1024 GF_FREE (rpc)__gf_free (rpc);
1025 rpc = NULL((void*)0);
1026 goto out;
1027 }
1028
1029 rpc->saved_frames_pool = mem_pool_new (struct saved_frame,mem_pool_new_fn (sizeof(struct saved_frame), reqpool_size, "struct saved_frame"
)
1030 reqpool_size)mem_pool_new_fn (sizeof(struct saved_frame), reqpool_size, "struct saved_frame"
)
;
1031 if (rpc->saved_frames_pool == NULL((void*)0)) {
1032 pthread_mutex_destroy (&rpc->lock);
1033 mem_pool_destroy (rpc->reqpool);
1034 GF_FREE (rpc)__gf_free (rpc);
1035 rpc = NULL((void*)0);
1036 goto out;
1037 }
1038
1039 ret = rpc_clnt_connection_init (rpc, ctx, options, name);
1040 if (ret == -1) {
1041 pthread_mutex_destroy (&rpc->lock);
1042 mem_pool_destroy (rpc->reqpool);
1043 mem_pool_destroy (rpc->saved_frames_pool);
1044 GF_FREE (rpc)__gf_free (rpc);
1045 rpc = NULL((void*)0);
1046 if (options)
1047 dict_unref (options);
1048 goto out;
1049 }
1050
1051 rpc->auth_null = dict_get_str_boolean (options, "auth-null", 0);
1052
1053 rpc = rpc_clnt_ref (rpc);
1054 INIT_LIST_HEAD (&rpc->programs)do { (&rpc->programs)->next = (&rpc->programs
)->prev = &rpc->programs; } while (0)
;
1055
1056out:
1057 return rpc;
1058}
1059
1060
1061int
1062rpc_clnt_start (struct rpc_clnt *rpc)
1063{
1064 struct rpc_clnt_connection *conn = NULL((void*)0);
1065
1066 if (!rpc)
1067 return -1;
1068
1069 conn = &rpc->conn;
1070
1071 rpc_clnt_reconnect (conn->trans);
1072
1073 return 0;
1074}
1075
1076
1077int
1078rpc_clnt_register_notify (struct rpc_clnt *rpc, rpc_clnt_notify_t fn,
1079 void *mydata)
1080{
1081 rpc->mydata = mydata;
1082 rpc->notifyfn = fn;
1083
1084 return 0;
1085}
1086
1087ssize_t
1088xdr_serialize_glusterfs_auth (char *dest, struct auth_glusterfs_parms_v2 *au)
1089{
1090 ssize_t ret = -1;
1091 XDR xdr;
1092
1093 if ((!dest) || (!au))
1094 return -1;
1095
1096 xdrmem_create (&xdr, dest, GF_MAX_AUTH_BYTES2048, XDR_ENCODE);
1097
1098 if (!xdr_auth_glusterfs_parms_v2 (&xdr, au)) {
1099 gf_log (THIS->name, GF_LOG_WARNING,do { do { if (0) printf ("failed to encode auth glusterfs elements"
); } while (0); _gf_log ((*__glusterfs_this_location())->name
, "rpc-clnt.c", __FUNCTION__, 1100, GF_LOG_WARNING, "failed to encode auth glusterfs elements"
); } while (0)
1100 "failed to encode auth glusterfs elements")do { do { if (0) printf ("failed to encode auth glusterfs elements"
); } while (0); _gf_log ((*__glusterfs_this_location())->name
, "rpc-clnt.c", __FUNCTION__, 1100, GF_LOG_WARNING, "failed to encode auth glusterfs elements"
); } while (0)
;
1101 ret = -1;
1102 goto ret;
1103 }
1104
1105 ret = (((size_t)(&xdr)->x_private) - ((size_t)(&xdr)->x_base));
1106
1107ret:
1108 return ret;
1109}
1110
1111
1112int
1113rpc_clnt_fill_request (int prognum, int progver, int procnum,
1114 uint64_t xid, struct auth_glusterfs_parms_v2 *au,
1115 struct rpc_msg *request, char *auth_data)
1116{
1117 int ret = -1;
1118
1119 if (!request) {
1120 goto out;
1121 }
1122
1123 memset (request, 0, sizeof (*request));
1124
1125 request->rm_xid = xid;
1126 request->rm_direction = CALL;
1127
1128 request->rm_callru.RM_cmb.cb_rpcvers = 2;
1129 request->rm_callru.RM_cmb.cb_prog = prognum;
1130 request->rm_callru.RM_cmb.cb_vers = progver;
1131 request->rm_callru.RM_cmb.cb_proc = procnum;
1132
1133 /* TODO: Using AUTH_(GLUSTERFS/NULL) in a kludgy way for time-being.
1134 * Make it modular in future so it is easy to plug-in new
1135 * authentication schemes.
1136 */
1137 if (auth_data) {
1138 ret = xdr_serialize_glusterfs_auth (auth_data, au);
1139 if (ret == -1) {
1140 gf_log ("rpc-clnt", GF_LOG_DEBUG,do { do { if (0) printf ("cannot encode credentials"); } while
(0); _gf_log ("rpc-clnt", "rpc-clnt.c", __FUNCTION__, 1141, GF_LOG_DEBUG
, "cannot encode credentials"); } while (0)
1141 "cannot encode credentials")do { do { if (0) printf ("cannot encode credentials"); } while
(0); _gf_log ("rpc-clnt", "rpc-clnt.c", __FUNCTION__, 1141, GF_LOG_DEBUG
, "cannot encode credentials"); } while (0)
;
1142 goto out;
1143 }
1144
1145 request->rm_callru.RM_cmb.cb_cred.oa_flavor = AUTH_GLUSTERFS_v2;
1146 request->rm_callru.RM_cmb.cb_cred.oa_base = auth_data;
1147 request->rm_callru.RM_cmb.cb_cred.oa_length = ret;
1148 } else {
1149 request->rm_callru.RM_cmb.cb_cred.oa_flavor = AUTH_NULL0;
1150 request->rm_callru.RM_cmb.cb_cred.oa_base = NULL((void*)0);
1151 request->rm_callru.RM_cmb.cb_cred.oa_length = 0;
1152 }
1153 request->rm_callru.RM_cmb.cb_verf.oa_flavor = AUTH_NONE0;
1154 request->rm_callru.RM_cmb.cb_verf.oa_base = NULL((void*)0);
1155 request->rm_callru.RM_cmb.cb_verf.oa_length = 0;
1156
1157 ret = 0;
1158out:
1159 return ret;
1160}
1161
1162
1163struct iovec
1164rpc_clnt_record_build_header (char *recordstart, size_t rlen,
1165 struct rpc_msg *request, size_t payload)
1166{
1167 struct iovec requesthdr = {0, };
1168 struct iovec txrecord = {0, 0};
1169 int ret = -1;
1170 size_t fraglen = 0;
1171
1172 ret = rpc_request_to_xdr (request, recordstart, rlen, &requesthdr);
1173 if (ret == -1) {
1174 gf_log ("rpc-clnt", GF_LOG_DEBUG,do { do { if (0) printf ("Failed to create RPC request"); } while
(0); _gf_log ("rpc-clnt", "rpc-clnt.c", __FUNCTION__, 1175, GF_LOG_DEBUG
, "Failed to create RPC request"); } while (0)
1175 "Failed to create RPC request")do { do { if (0) printf ("Failed to create RPC request"); } while
(0); _gf_log ("rpc-clnt", "rpc-clnt.c", __FUNCTION__, 1175, GF_LOG_DEBUG
, "Failed to create RPC request"); } while (0)
;
1176 goto out;
1177 }
1178
1179 fraglen = payload + requesthdr.iov_len;
1180 gf_log ("rpc-clnt", GF_LOG_TRACE, "Request fraglen %zu, payload: %zu, "do { do { if (0) printf ("Request fraglen %zu, payload: %zu, "
"rpc hdr: %zu", fraglen, payload, requesthdr.iov_len); } while
(0); _gf_log ("rpc-clnt", "rpc-clnt.c", __FUNCTION__, 1181, GF_LOG_TRACE
, "Request fraglen %zu, payload: %zu, " "rpc hdr: %zu", fraglen
, payload, requesthdr.iov_len); } while (0)
1181 "rpc hdr: %zu", fraglen, payload, requesthdr.iov_len)do { do { if (0) printf ("Request fraglen %zu, payload: %zu, "
"rpc hdr: %zu", fraglen, payload, requesthdr.iov_len); } while
(0); _gf_log ("rpc-clnt", "rpc-clnt.c", __FUNCTION__, 1181, GF_LOG_TRACE
, "Request fraglen %zu, payload: %zu, " "rpc hdr: %zu", fraglen
, payload, requesthdr.iov_len); } while (0)
;
1182
1183
1184 txrecord.iov_base = recordstart;
1185
1186 /* Remember, this is only the vec for the RPC header and does not
1187 * include the payload above. We needed the payload only to calculate
1188 * the size of the full fragment. This size is sent in the fragment
1189 * header.
1190 */
1191 txrecord.iov_len = requesthdr.iov_len;
1192
1193out:
1194 return txrecord;
1195}
1196
1197
1198struct iobuf *
1199rpc_clnt_record_build_record (struct rpc_clnt *clnt, int prognum, int progver,
1200 int procnum, size_t hdrsize, uint64_t xid,
1201 struct auth_glusterfs_parms_v2 *au,
1202 struct iovec *recbuf)
1203{
1204 struct rpc_msg request = {0, };
1205 struct iobuf *request_iob = NULL((void*)0);
1206 char *record = NULL((void*)0);
1207 struct iovec recordhdr = {0, };
1208 size_t pagesize = 0;
1209 int ret = -1;
1210 size_t xdr_size = 0;
1211 char auth_data[GF_MAX_AUTH_BYTES2048] = {0, };
1212
1213 if ((!clnt) || (!recbuf) || (!au)) {
1214 goto out;
1215 }
1216
1217 /* Fill the rpc structure and XDR it into the buffer got above. */
1218 if (clnt->auth_null)
1219 ret = rpc_clnt_fill_request (prognum, progver, procnum,
1220 xid, NULL((void*)0), &request, NULL((void*)0));
1221 else
1222 ret = rpc_clnt_fill_request (prognum, progver, procnum,
1223 xid, au, &request, auth_data);
1224
1225 if (ret == -1) {
1226 gf_log (clnt->conn.trans->name, GF_LOG_WARNING,do { do { if (0) printf ("cannot build a rpc-request xid (%""ll"
"u"")", xid); } while (0); _gf_log (clnt->conn.trans->
name, "rpc-clnt.c", __FUNCTION__, 1227, GF_LOG_WARNING, "cannot build a rpc-request xid (%"
"ll" "u"")", xid); } while (0)
1227 "cannot build a rpc-request xid (%"PRIu64")", xid)do { do { if (0) printf ("cannot build a rpc-request xid (%""ll"
"u"")", xid); } while (0); _gf_log (clnt->conn.trans->
name, "rpc-clnt.c", __FUNCTION__, 1227, GF_LOG_WARNING, "cannot build a rpc-request xid (%"
"ll" "u"")", xid); } while (0)
;
1228 goto out;
1229 }
1230
1231 xdr_size = xdr_sizeof ((xdrproc_t)xdr_callmsg, &request);
1232
1233 /* First, try to get a pointer into the buffer which the RPC
1234 * layer can use.
1235 */
1236 request_iob = iobuf_get2 (clnt->ctx->iobuf_pool, (xdr_size + hdrsize));
1237 if (!request_iob) {
1238 goto out;
1239 }
1240
1241 pagesize = iobuf_pagesize (request_iob)(request_iob->iobuf_arena->page_size);
1242
1243 record = iobuf_ptr (request_iob)((request_iob)->ptr); /* Now we have it. */
1244
1245 recordhdr = rpc_clnt_record_build_header (record, pagesize, &request,
1246 hdrsize);
1247
1248 if (!recordhdr.iov_base) {
1249 gf_log (clnt->conn.trans->name, GF_LOG_ERROR,do { do { if (0) printf ("Failed to build record header"); } while
(0); _gf_log (clnt->conn.trans->name, "rpc-clnt.c", __FUNCTION__
, 1250, GF_LOG_ERROR, "Failed to build record header"); } while
(0)
1250 "Failed to build record header")do { do { if (0) printf ("Failed to build record header"); } while
(0); _gf_log (clnt->conn.trans->name, "rpc-clnt.c", __FUNCTION__
, 1250, GF_LOG_ERROR, "Failed to build record header"); } while
(0)
;
1251 iobuf_unref (request_iob);
1252 request_iob = NULL((void*)0);
1253 recbuf->iov_base = NULL((void*)0);
1254 goto out;
1255 }
1256
1257 recbuf->iov_base = recordhdr.iov_base;
1258 recbuf->iov_len = recordhdr.iov_len;
1259
1260out:
1261 return request_iob;
1262}
1263
1264
1265struct iobuf *
1266rpc_clnt_record (struct rpc_clnt *clnt, call_frame_t *call_frame,
1267 rpc_clnt_prog_t *prog, int procnum, size_t hdrlen,
1268 struct iovec *rpchdr, uint64_t callid)
1269{
1270 struct auth_glusterfs_parms_v2 au = {0, };
1271 struct iobuf *request_iob = NULL((void*)0);
1272 char owner[4] = {0,};
1273
1274 if (!prog || !rpchdr || !call_frame) {
1275 goto out;
1276 }
1277
1278 au.pid = call_frame->root->pid;
1279 au.uid = call_frame->root->uid;
1280 au.gid = call_frame->root->gid;
1281 au.groups.groups_len = call_frame->root->ngrps;
1282 au.lk_owner.lk_owner_len = call_frame->root->lk_owner.len;
1283
1284 if (au.groups.groups_len)
1285 au.groups.groups_val = call_frame->root->groups;
1286
1287 if (call_frame->root->lk_owner.len)
1288 au.lk_owner.lk_owner_val = call_frame->root->lk_owner.data;
1289 else {
1290 owner[0] = (char)(au.pid & 0xff);
1291 owner[1] = (char)((au.pid >> 8) & 0xff);
1292 owner[2] = (char)((au.pid >> 16) & 0xff);
1293 owner[3] = (char)((au.pid >> 24) & 0xff);
1294
1295 au.lk_owner.lk_owner_val = owner;
1296 au.lk_owner.lk_owner_len = 4;
1297 }
1298
1299 gf_log (clnt->conn.trans->name, GF_LOG_TRACE, "Auth Info: pid: %u, uid: %d"do { do { if (0) printf ("Auth Info: pid: %u, uid: %d" ", gid: %d, owner: %s"
, au.pid, au.uid, au.gid, lkowner_utoa (&call_frame->root
->lk_owner)); } while (0); _gf_log (clnt->conn.trans->
name, "rpc-clnt.c", __FUNCTION__, 1301, GF_LOG_TRACE, "Auth Info: pid: %u, uid: %d"
", gid: %d, owner: %s", au.pid, au.uid, au.gid, lkowner_utoa
(&call_frame->root->lk_owner)); } while (0)
1300 ", gid: %d, owner: %s", au.pid, au.uid, au.gid,do { do { if (0) printf ("Auth Info: pid: %u, uid: %d" ", gid: %d, owner: %s"
, au.pid, au.uid, au.gid, lkowner_utoa (&call_frame->root
->lk_owner)); } while (0); _gf_log (clnt->conn.trans->
name, "rpc-clnt.c", __FUNCTION__, 1301, GF_LOG_TRACE, "Auth Info: pid: %u, uid: %d"
", gid: %d, owner: %s", au.pid, au.uid, au.gid, lkowner_utoa
(&call_frame->root->lk_owner)); } while (0)
1301 lkowner_utoa (&call_frame->root->lk_owner))do { do { if (0) printf ("Auth Info: pid: %u, uid: %d" ", gid: %d, owner: %s"
, au.pid, au.uid, au.gid, lkowner_utoa (&call_frame->root
->lk_owner)); } while (0); _gf_log (clnt->conn.trans->
name, "rpc-clnt.c", __FUNCTION__, 1301, GF_LOG_TRACE, "Auth Info: pid: %u, uid: %d"
", gid: %d, owner: %s", au.pid, au.uid, au.gid, lkowner_utoa
(&call_frame->root->lk_owner)); } while (0)
;
1302
1303 request_iob = rpc_clnt_record_build_record (clnt, prog->prognum,
1304 prog->progver,
1305 procnum, hdrlen,
1306 callid, &au,
1307 rpchdr);
1308 if (!request_iob) {
1309 gf_log (clnt->conn.trans->name, GF_LOG_WARNING,do { do { if (0) printf ("cannot build rpc-record"); } while (
0); _gf_log (clnt->conn.trans->name, "rpc-clnt.c", __FUNCTION__
, 1310, GF_LOG_WARNING, "cannot build rpc-record"); } while (
0)
1310 "cannot build rpc-record")do { do { if (0) printf ("cannot build rpc-record"); } while (
0); _gf_log (clnt->conn.trans->name, "rpc-clnt.c", __FUNCTION__
, 1310, GF_LOG_WARNING, "cannot build rpc-record"); } while (
0)
;
1311 goto out;
1312 }
1313
1314out:
1315 return request_iob;
1316}
1317
1318int
1319rpcclnt_cbk_program_register (struct rpc_clnt *clnt,
1320 rpcclnt_cb_program_t *program, void *mydata)
1321{
1322 int ret = -1;
1323 char already_registered = 0;
1324 rpcclnt_cb_program_t *tmp = NULL((void*)0);
1325
1326 if (!clnt)
1327 goto out;
1328
1329 if (program->actors == NULL((void*)0))
1330 goto out;
1331
1332 pthread_mutex_lock (&clnt->lock);
1333 {
1334 list_for_each_entry (tmp, &clnt->programs, program)for (tmp = ((typeof(*tmp) *)((char *)((&clnt->programs
)->next)-(unsigned long)(&((typeof(*tmp) *)0)->program
))); &tmp->program != (&clnt->programs); tmp = (
(typeof(*tmp) *)((char *)(tmp->program.next)-(unsigned long
)(&((typeof(*tmp) *)0)->program))))
{
1335 if ((program->prognum == tmp->prognum)
1336 && (program->progver == tmp->progver)) {
1337 already_registered = 1;
1338 break;
1339 }
1340 }
1341 }
1342 pthread_mutex_unlock (&clnt->lock);
1343
1344 if (already_registered) {
1345 gf_log_callingfn (clnt->conn.trans->name, GF_LOG_DEBUG,do { do { if (0) printf ("already registered"); } while (0); _gf_log_callingfn
(clnt->conn.trans->name, "rpc-clnt.c", __FUNCTION__, 1346
, GF_LOG_DEBUG, "already registered"); } while (0)
1346 "already registered")do { do { if (0) printf ("already registered"); } while (0); _gf_log_callingfn
(clnt->conn.trans->name, "rpc-clnt.c", __FUNCTION__, 1346
, GF_LOG_DEBUG, "already registered"); } while (0)
;
1347 ret = 0;
1348 goto out;
1349 }
1350
1351 tmp = GF_CALLOC (1, sizeof (*tmp),__gf_calloc (1, sizeof (*tmp), gf_common_mt_rpcclnt_cb_program_t
)
1352 gf_common_mt_rpcclnt_cb_program_t)__gf_calloc (1, sizeof (*tmp), gf_common_mt_rpcclnt_cb_program_t
)
;
1353 if (tmp == NULL((void*)0)) {
1354 goto out;
1355 }
1356
1357 memcpy (tmp, program, sizeof (*tmp));
1358 INIT_LIST_HEAD (&tmp->program)do { (&tmp->program)->next = (&tmp->program)
->prev = &tmp->program; } while (0)
;
1359
1360 tmp->mydata = mydata;
1361
1362 pthread_mutex_lock (&clnt->lock);
1363 {
1364 list_add_tail (&tmp->program, &clnt->programs);
1365 }
1366 pthread_mutex_unlock (&clnt->lock);
1367
1368 ret = 0;
1369 gf_log (clnt->conn.trans->name, GF_LOG_DEBUG,do { do { if (0) printf ("New program registered: %s, Num: %d, Ver: %d"
, program->progname, program->prognum, program->progver
); } while (0); _gf_log (clnt->conn.trans->name, "rpc-clnt.c"
, __FUNCTION__, 1372, GF_LOG_DEBUG, "New program registered: %s, Num: %d, Ver: %d"
, program->progname, program->prognum, program->progver
); } while (0)
1370 "New program registered: %s, Num: %d, Ver: %d",do { do { if (0) printf ("New program registered: %s, Num: %d, Ver: %d"
, program->progname, program->prognum, program->progver
); } while (0); _gf_log (clnt->conn.trans->name, "rpc-clnt.c"
, __FUNCTION__, 1372, GF_LOG_DEBUG, "New program registered: %s, Num: %d, Ver: %d"
, program->progname, program->prognum, program->progver
); } while (0)
1371 program->progname, program->prognum,do { do { if (0) printf ("New program registered: %s, Num: %d, Ver: %d"
, program->progname, program->prognum, program->progver
); } while (0); _gf_log (clnt->conn.trans->name, "rpc-clnt.c"
, __FUNCTION__, 1372, GF_LOG_DEBUG, "New program registered: %s, Num: %d, Ver: %d"
, program->progname, program->prognum, program->progver
); } while (0)
1372 program->progver)do { do { if (0) printf ("New program registered: %s, Num: %d, Ver: %d"
, program->progname, program->prognum, program->progver
); } while (0); _gf_log (clnt->conn.trans->name, "rpc-clnt.c"
, __FUNCTION__, 1372, GF_LOG_DEBUG, "New program registered: %s, Num: %d, Ver: %d"
, program->progname, program->prognum, program->progver
); } while (0)
;
1373
1374out:
1375 if (ret == -1) {
1376 gf_log (clnt->conn.trans->name, GF_LOG_ERROR,do { do { if (0) printf ("Program registration failed:" " %s, Num: %d, Ver: %d"
, program->progname, program->prognum, program->progver
); } while (0); _gf_log (clnt->conn.trans->name, "rpc-clnt.c"
, __FUNCTION__, 1379, GF_LOG_ERROR, "Program registration failed:"
" %s, Num: %d, Ver: %d", program->progname, program->prognum
, program->progver); } while (0)
1377 "Program registration failed:"do { do { if (0) printf ("Program registration failed:" " %s, Num: %d, Ver: %d"
, program->progname, program->prognum, program->progver
); } while (0); _gf_log (clnt->conn.trans->name, "rpc-clnt.c"
, __FUNCTION__, 1379, GF_LOG_ERROR, "Program registration failed:"
" %s, Num: %d, Ver: %d", program->progname, program->prognum
, program->progver); } while (0)
1378 " %s, Num: %d, Ver: %d", program->progname,do { do { if (0) printf ("Program registration failed:" " %s, Num: %d, Ver: %d"
, program->progname, program->prognum, program->progver
); } while (0); _gf_log (clnt->conn.trans->name, "rpc-clnt.c"
, __FUNCTION__, 1379, GF_LOG_ERROR, "Program registration failed:"
" %s, Num: %d, Ver: %d", program->progname, program->prognum
, program->progver); } while (0)
1379 program->prognum, program->progver)do { do { if (0) printf ("Program registration failed:" " %s, Num: %d, Ver: %d"
, program->progname, program->prognum, program->progver
); } while (0); _gf_log (clnt->conn.trans->name, "rpc-clnt.c"
, __FUNCTION__, 1379, GF_LOG_ERROR, "Program registration failed:"
" %s, Num: %d, Ver: %d", program->progname, program->prognum
, program->progver); } while (0)
;
1380 }
1381
1382 return ret;
1383}
1384
1385
1386int
1387rpc_clnt_submit (struct rpc_clnt *rpc, rpc_clnt_prog_t *prog,
1388 int procnum, fop_cbk_fn_t cbkfn,
1389 struct iovec *proghdr, int proghdrcount,
1390 struct iovec *progpayload, int progpayloadcount,
1391 struct iobref *iobref, void *frame, struct iovec *rsphdr,
1392 int rsphdr_count, struct iovec *rsp_payload,
1393 int rsp_payload_count, struct iobref *rsp_iobref)
1394{
1395 rpc_clnt_connection_t *conn = NULL((void*)0);
1396 struct iobuf *request_iob = NULL((void*)0);
1397 struct iovec rpchdr = {0,};
1398 struct rpc_req *rpcreq = NULL((void*)0);
1399 rpc_transport_req_t req;
1400 int ret = -1;
1401 int proglen = 0;
1402 char new_iobref = 0;
1403 uint64_t callid = 0;
1404
1405 if (!rpc || !prog || !frame) {
1406 goto out;
1407 }
1408
1409 conn = &rpc->conn;
1410
1411 if (conn->trans == NULL((void*)0)) {
1412 goto out;
1413 }
1414
1415 rpcreq = mem_get (rpc->reqpool);
1416 if (rpcreq == NULL((void*)0)) {
1417 goto out;
1418 }
1419
1420 memset (rpcreq, 0, sizeof (*rpcreq));
1421 memset (&req, 0, sizeof (req));
1422
1423 if (!iobref) {
1424 iobref = iobref_new ();
1425 if (!iobref) {
1426 goto out;
1427 }
1428
1429 new_iobref = 1;
1430 }
1431
1432 callid = rpc_clnt_new_callid (rpc);
1433
1434 rpcreq->prog = prog;
1435 rpcreq->procnum = procnum;
1436 rpcreq->conn = conn;
1437 rpcreq->xid = callid;
1438 rpcreq->cbkfn = cbkfn;
1439
1440 ret = -1;
1441
1442 if (proghdr) {
1443 proglen += iov_length (proghdr, proghdrcount);
1444 }
1445
1446 request_iob = rpc_clnt_record (rpc, frame, prog,
1447 procnum, proglen,
1448 &rpchdr, callid);
1449 if (!request_iob) {
1450 gf_log (conn->trans->name, GF_LOG_WARNING,do { do { if (0) printf ("cannot build rpc-record"); } while (
0); _gf_log (conn->trans->name, "rpc-clnt.c", __FUNCTION__
, 1451, GF_LOG_WARNING, "cannot build rpc-record"); } while (
0)
1451 "cannot build rpc-record")do { do { if (0) printf ("cannot build rpc-record"); } while (
0); _gf_log (conn->trans->name, "rpc-clnt.c", __FUNCTION__
, 1451, GF_LOG_WARNING, "cannot build rpc-record"); } while (
0)
;
1452 goto out;
1453 }
1454
1455 iobref_add (iobref, request_iob);
1456
1457 req.msg.rpchdr = &rpchdr;
1458 req.msg.rpchdrcount = 1;
1459 req.msg.proghdr = proghdr;
1460 req.msg.proghdrcount = proghdrcount;
1461 req.msg.progpayload = progpayload;
1462 req.msg.progpayloadcount = progpayloadcount;
1463 req.msg.iobref = iobref;
1464
1465 req.rsp.rsphdr = rsphdr;
1466 req.rsp.rsphdr_count = rsphdr_count;
1467 req.rsp.rsp_payload = rsp_payload;
1468 req.rsp.rsp_payload_count = rsp_payload_count;
1469 req.rsp.rsp_iobref = rsp_iobref;
1470 req.rpc_req = rpcreq;
1471
1472 pthread_mutex_lock (&conn->lock);
1473 {
1474 if (conn->connected == 0) {
1475 ret = rpc_transport_connect (conn->trans,
1476 conn->config.remote_port);
1477 }
1478
1479 ret = rpc_transport_submit_request (rpc->conn.trans,
1480 &req);
1481 if (ret == -1) {
1482 gf_log (conn->trans->name, GF_LOG_WARNING,do { do { if (0) printf ("failed to submit rpc-request " "(XID: 0x%ux Program: %s, ProgVers: %d, "
"Proc: %d) to rpc-transport (%s)", rpcreq->xid, rpcreq->
prog->progname, rpcreq->prog->progver, rpcreq->procnum
, rpc->conn.trans->name); } while (0); _gf_log (conn->
trans->name, "rpc-clnt.c", __FUNCTION__, 1487, GF_LOG_WARNING
, "failed to submit rpc-request " "(XID: 0x%ux Program: %s, ProgVers: %d, "
"Proc: %d) to rpc-transport (%s)", rpcreq->xid, rpcreq->
prog->progname, rpcreq->prog->progver, rpcreq->procnum
, rpc->conn.trans->name); } while (0)
1483 "failed to submit rpc-request "do { do { if (0) printf ("failed to submit rpc-request " "(XID: 0x%ux Program: %s, ProgVers: %d, "
"Proc: %d) to rpc-transport (%s)", rpcreq->xid, rpcreq->
prog->progname, rpcreq->prog->progver, rpcreq->procnum
, rpc->conn.trans->name); } while (0); _gf_log (conn->
trans->name, "rpc-clnt.c", __FUNCTION__, 1487, GF_LOG_WARNING
, "failed to submit rpc-request " "(XID: 0x%ux Program: %s, ProgVers: %d, "
"Proc: %d) to rpc-transport (%s)", rpcreq->xid, rpcreq->
prog->progname, rpcreq->prog->progver, rpcreq->procnum
, rpc->conn.trans->name); } while (0)
1484 "(XID: 0x%ux Program: %s, ProgVers: %d, "do { do { if (0) printf ("failed to submit rpc-request " "(XID: 0x%ux Program: %s, ProgVers: %d, "
"Proc: %d) to rpc-transport (%s)", rpcreq->xid, rpcreq->
prog->progname, rpcreq->prog->progver, rpcreq->procnum
, rpc->conn.trans->name); } while (0); _gf_log (conn->
trans->name, "rpc-clnt.c", __FUNCTION__, 1487, GF_LOG_WARNING
, "failed to submit rpc-request " "(XID: 0x%ux Program: %s, ProgVers: %d, "
"Proc: %d) to rpc-transport (%s)", rpcreq->xid, rpcreq->
prog->progname, rpcreq->prog->progver, rpcreq->procnum
, rpc->conn.trans->name); } while (0)
1485 "Proc: %d) to rpc-transport (%s)", rpcreq->xid,do { do { if (0) printf ("failed to submit rpc-request " "(XID: 0x%ux Program: %s, ProgVers: %d, "
"Proc: %d) to rpc-transport (%s)", rpcreq->xid, rpcreq->
prog->progname, rpcreq->prog->progver, rpcreq->procnum
, rpc->conn.trans->name); } while (0); _gf_log (conn->
trans->name, "rpc-clnt.c", __FUNCTION__, 1487, GF_LOG_WARNING
, "failed to submit rpc-request " "(XID: 0x%ux Program: %s, ProgVers: %d, "
"Proc: %d) to rpc-transport (%s)", rpcreq->xid, rpcreq->
prog->progname, rpcreq->prog->progver, rpcreq->procnum
, rpc->conn.trans->name); } while (0)
1486 rpcreq->prog->progname, rpcreq->prog->progver,do { do { if (0) printf ("failed to submit rpc-request " "(XID: 0x%ux Program: %s, ProgVers: %d, "
"Proc: %d) to rpc-transport (%s)", rpcreq->xid, rpcreq->
prog->progname, rpcreq->prog->progver, rpcreq->procnum
, rpc->conn.trans->name); } while (0); _gf_log (conn->
trans->name, "rpc-clnt.c", __FUNCTION__, 1487, GF_LOG_WARNING
, "failed to submit rpc-request " "(XID: 0x%ux Program: %s, ProgVers: %d, "
"Proc: %d) to rpc-transport (%s)", rpcreq->xid, rpcreq->
prog->progname, rpcreq->prog->progver, rpcreq->procnum
, rpc->conn.trans->name); } while (0)
1487 rpcreq->procnum, rpc->conn.trans->name)do { do { if (0) printf ("failed to submit rpc-request " "(XID: 0x%ux Program: %s, ProgVers: %d, "
"Proc: %d) to rpc-transport (%s)", rpcreq->xid, rpcreq->
prog->progname, rpcreq->prog->progver, rpcreq->procnum
, rpc->conn.trans->name); } while (0); _gf_log (conn->
trans->name, "rpc-clnt.c", __FUNCTION__, 1487, GF_LOG_WARNING
, "failed to submit rpc-request " "(XID: 0x%ux Program: %s, ProgVers: %d, "
"Proc: %d) to rpc-transport (%s)", rpcreq->xid, rpcreq->
prog->progname, rpcreq->prog->progver, rpcreq->procnum
, rpc->conn.trans->name); } while (0)
;
1488 }
1489
1490 if ((ret >= 0) && frame) {
1491 /* Save the frame in queue */
1492 __save_frame (rpc, frame, rpcreq);
1493
1494 gf_log ("rpc-clnt", GF_LOG_TRACE, "submitted request "do { do { if (0) printf ("submitted request " "(XID: 0x%ux Program: %s, ProgVers: %d, "
"Proc: %d) to rpc-transport (%s)", rpcreq->xid, rpcreq->
prog->progname, rpcreq->prog->progver, rpcreq->procnum
, rpc->conn.trans->name); } while (0); _gf_log ("rpc-clnt"
, "rpc-clnt.c", __FUNCTION__, 1498, GF_LOG_TRACE, "submitted request "
"(XID: 0x%ux Program: %s, ProgVers: %d, " "Proc: %d) to rpc-transport (%s)"
, rpcreq->xid, rpcreq->prog->progname, rpcreq->prog
->progver, rpcreq->procnum, rpc->conn.trans->name
); } while (0)
1495 "(XID: 0x%ux Program: %s, ProgVers: %d, "do { do { if (0) printf ("submitted request " "(XID: 0x%ux Program: %s, ProgVers: %d, "
"Proc: %d) to rpc-transport (%s)", rpcreq->xid, rpcreq->
prog->progname, rpcreq->prog->progver, rpcreq->procnum
, rpc->conn.trans->name); } while (0); _gf_log ("rpc-clnt"
, "rpc-clnt.c", __FUNCTION__, 1498, GF_LOG_TRACE, "submitted request "
"(XID: 0x%ux Program: %s, ProgVers: %d, " "Proc: %d) to rpc-transport (%s)"
, rpcreq->xid, rpcreq->prog->progname, rpcreq->prog
->progver, rpcreq->procnum, rpc->conn.trans->name
); } while (0)
1496 "Proc: %d) to rpc-transport (%s)", rpcreq->xid,do { do { if (0) printf ("submitted request " "(XID: 0x%ux Program: %s, ProgVers: %d, "
"Proc: %d) to rpc-transport (%s)", rpcreq->xid, rpcreq->
prog->progname, rpcreq->prog->progver, rpcreq->procnum
, rpc->conn.trans->name); } while (0); _gf_log ("rpc-clnt"
, "rpc-clnt.c", __FUNCTION__, 1498, GF_LOG_TRACE, "submitted request "
"(XID: 0x%ux Program: %s, ProgVers: %d, " "Proc: %d) to rpc-transport (%s)"
, rpcreq->xid, rpcreq->prog->progname, rpcreq->prog
->progver, rpcreq->procnum, rpc->conn.trans->name
); } while (0)
1497 rpcreq->prog->progname, rpcreq->prog->progver,do { do { if (0) printf ("submitted request " "(XID: 0x%ux Program: %s, ProgVers: %d, "
"Proc: %d) to rpc-transport (%s)", rpcreq->xid, rpcreq->
prog->progname, rpcreq->prog->progver, rpcreq->procnum
, rpc->conn.trans->name); } while (0); _gf_log ("rpc-clnt"
, "rpc-clnt.c", __FUNCTION__, 1498, GF_LOG_TRACE, "submitted request "
"(XID: 0x%ux Program: %s, ProgVers: %d, " "Proc: %d) to rpc-transport (%s)"
, rpcreq->xid, rpcreq->prog->progname, rpcreq->prog
->progver, rpcreq->procnum, rpc->conn.trans->name
); } while (0)
1498 rpcreq->procnum, rpc->conn.trans->name)do { do { if (0) printf ("submitted request " "(XID: 0x%ux Program: %s, ProgVers: %d, "
"Proc: %d) to rpc-transport (%s)", rpcreq->xid, rpcreq->
prog->progname, rpcreq->prog->progver, rpcreq->procnum
, rpc->conn.trans->name); } while (0); _gf_log ("rpc-clnt"
, "rpc-clnt.c", __FUNCTION__, 1498, GF_LOG_TRACE, "submitted request "
"(XID: 0x%ux Program: %s, ProgVers: %d, " "Proc: %d) to rpc-transport (%s)"
, rpcreq->xid, rpcreq->prog->progname, rpcreq->prog
->progver, rpcreq->procnum, rpc->conn.trans->name
); } while (0)
;
1499 }
1500 }
1501 pthread_mutex_unlock (&conn->lock);
1502
1503 if (ret == -1) {
1504 goto out;
1505 }
1506
1507 ret = 0;
1508
1509out:
1510 if (request_iob) {
1511 iobuf_unref (request_iob);
1512 }
1513
1514 if (new_iobref && iobref) {
1515 iobref_unref (iobref);
1516 }
1517
1518 if (frame && (ret == -1)) {
1519 if (rpcreq) {
1520 rpcreq->rpc_status = -1;
1521 cbkfn (rpcreq, NULL((void*)0), 0, frame);
1522 mem_put (rpcreq);
1523 }
1524 }
1525 return ret;
1526}
1527
1528
1529struct rpc_clnt *
1530rpc_clnt_ref (struct rpc_clnt *rpc)
1531{
1532 if (!rpc)
1533 return NULL((void*)0);
1534 pthread_mutex_lock (&rpc->lock);
1535 {
1536 rpc->refcount++;
1537 }
1538 pthread_mutex_unlock (&rpc->lock);
1539 return rpc;
1540}
1541
1542
1543static void
1544rpc_clnt_destroy (struct rpc_clnt *rpc)
1545{
1546 if (!rpc)
1547 return;
1548
1549 if (rpc->conn.trans) {
1550 rpc_transport_unregister_notify (rpc->conn.trans);
1551 rpc_transport_disconnect (rpc->conn.trans);
1552 rpc_transport_unref (rpc->conn.trans);
1553 }
1554
1555 rpc_clnt_reconnect_cleanup (&rpc->conn);
1556 saved_frames_destroy (rpc->conn.saved_frames);
1557 pthread_mutex_destroy (&rpc->lock);
1558 pthread_mutex_destroy (&rpc->conn.lock);
1559
1560 /* mem-pool should be destroyed, otherwise,
1561 it will cause huge memory leaks */
1562 mem_pool_destroy (rpc->reqpool);
1563 mem_pool_destroy (rpc->saved_frames_pool);
1564
1565 GF_FREE (rpc)__gf_free (rpc);
1566 return;
1567}
1568
1569struct rpc_clnt *
1570rpc_clnt_unref (struct rpc_clnt *rpc)
1571{
1572 int count = 0;
1573
1574 if (!rpc)
1575 return NULL((void*)0);
1576 pthread_mutex_lock (&rpc->lock);
1577 {
1578 count = --rpc->refcount;
1579 }
1580 pthread_mutex_unlock (&rpc->lock);
1581 if (!count) {
1582 rpc_clnt_destroy (rpc);
1583 return NULL((void*)0);
1584 }
1585 return rpc;
1586}
1587
1588
1589void
1590rpc_clnt_disable (struct rpc_clnt *rpc)
1591{
1592 rpc_clnt_connection_t *conn = NULL((void*)0);
1593
1594 if (!rpc) {
1595 goto out;
1596 }
1597
1598 conn = &rpc->conn;
1599
1600 pthread_mutex_lock (&conn->lock);
1601 {
1602 rpc->disabled = 1;
1603
1604 if (conn->timer) {
1605 gf_timer_call_cancel (rpc->ctx, conn->timer);
1606 conn->timer = NULL((void*)0);
1607 }
1608
1609 if (conn->reconnect) {
1610 gf_timer_call_cancel (rpc->ctx, conn->reconnect);
1611 conn->reconnect = NULL((void*)0);
1612 }
1613 conn->connected = 0;
1614
1615 if (conn->ping_timer) {
1616 gf_timer_call_cancel (rpc->ctx, conn->ping_timer);
1617 conn->ping_timer = NULL((void*)0);
1618 conn->ping_started = 0;
1619 }
1620
1621 }
1622 pthread_mutex_unlock (&conn->lock);
1623
1624 rpc_transport_disconnect (rpc->conn.trans);
1625
1626out:
1627 return;
1628}
1629
1630
1631void
1632rpc_clnt_reconfig (struct rpc_clnt *rpc, struct rpc_clnt_config *config)
1633{
1634 if (config->rpc_timeout) {
1635 if (config->rpc_timeout != rpc->conn.config.rpc_timeout)
1636 gf_log (rpc->conn.trans->name, GF_LOG_INFO,do { do { if (0) printf ("changing timeout to %d (from %d)", config
->rpc_timeout, rpc->conn.config.rpc_timeout); } while (
0); _gf_log (rpc->conn.trans->name, "rpc-clnt.c", __FUNCTION__
, 1639, GF_LOG_INFO, "changing timeout to %d (from %d)", config
->rpc_timeout, rpc->conn.config.rpc_timeout); } while (
0)
1637 "changing timeout to %d (from %d)",do { do { if (0) printf ("changing timeout to %d (from %d)", config
->rpc_timeout, rpc->conn.config.rpc_timeout); } while (
0); _gf_log (rpc->conn.trans->name, "rpc-clnt.c", __FUNCTION__
, 1639, GF_LOG_INFO, "changing timeout to %d (from %d)", config
->rpc_timeout, rpc->conn.config.rpc_timeout); } while (
0)
1638 config->rpc_timeout,do { do { if (0) printf ("changing timeout to %d (from %d)", config
->rpc_timeout, rpc->conn.config.rpc_timeout); } while (
0); _gf_log (rpc->conn.trans->name, "rpc-clnt.c", __FUNCTION__
, 1639, GF_LOG_INFO, "changing timeout to %d (from %d)", config
->rpc_timeout, rpc->conn.config.rpc_timeout); } while (
0)
1639 rpc->conn.config.rpc_timeout)do { do { if (0) printf ("changing timeout to %d (from %d)", config
->rpc_timeout, rpc->conn.config.rpc_timeout); } while (
0); _gf_log (rpc->conn.trans->name, "rpc-clnt.c", __FUNCTION__
, 1639, GF_LOG_INFO, "changing timeout to %d (from %d)", config
->rpc_timeout, rpc->conn.config.rpc_timeout); } while (
0)
;
1640 rpc->conn.config.rpc_timeout = config->rpc_timeout;
1641 }
1642
1643 if (config->remote_port) {
1644 if (config->remote_port != rpc->conn.config.remote_port)
1645 gf_log (rpc->conn.trans->name, GF_LOG_INFO,do { do { if (0) printf ("changing port to %d (from %d)", config
->remote_port, rpc->conn.config.remote_port); } while (
0); _gf_log (rpc->conn.trans->name, "rpc-clnt.c", __FUNCTION__
, 1648, GF_LOG_INFO, "changing port to %d (from %d)", config->
remote_port, rpc->conn.config.remote_port); } while (0)
1646 "changing port to %d (from %d)",do { do { if (0) printf ("changing port to %d (from %d)", config
->remote_port, rpc->conn.config.remote_port); } while (
0); _gf_log (rpc->conn.trans->name, "rpc-clnt.c", __FUNCTION__
, 1648, GF_LOG_INFO, "changing port to %d (from %d)", config->
remote_port, rpc->conn.config.remote_port); } while (0)
1647 config->remote_port,do { do { if (0) printf ("changing port to %d (from %d)", config
->remote_port, rpc->conn.config.remote_port); } while (
0); _gf_log (rpc->conn.trans->name, "rpc-clnt.c", __FUNCTION__
, 1648, GF_LOG_INFO, "changing port to %d (from %d)", config->
remote_port, rpc->conn.config.remote_port); } while (0)
1648 rpc->conn.config.remote_port)do { do { if (0) printf ("changing port to %d (from %d)", config
->remote_port, rpc->conn.config.remote_port); } while (
0); _gf_log (rpc->conn.trans->name, "rpc-clnt.c", __FUNCTION__
, 1648, GF_LOG_INFO, "changing port to %d (from %d)", config->
remote_port, rpc->conn.config.remote_port); } while (0)
;
1649
1650 rpc->conn.config.remote_port = config->remote_port;
1651 }
1652
1653 if (config->remote_host) {
1654 if (rpc->conn.config.remote_host) {
1655 if (strcmp (rpc->conn.config.remote_host,
1656 config->remote_host))
1657 gf_log (rpc->conn.trans->name, GF_LOG_INFO,do { do { if (0) printf ("changing hostname to %s (from %s)",
config->remote_host, rpc->conn.config.remote_host); } while
(0); _gf_log (rpc->conn.trans->name, "rpc-clnt.c", __FUNCTION__
, 1660, GF_LOG_INFO, "changing hostname to %s (from %s)", config
->remote_host, rpc->conn.config.remote_host); } while (
0)
1658 "changing hostname to %s (from %s)",do { do { if (0) printf ("changing hostname to %s (from %s)",
config->remote_host, rpc->conn.config.remote_host); } while
(0); _gf_log (rpc->conn.trans->name, "rpc-clnt.c", __FUNCTION__
, 1660, GF_LOG_INFO, "changing hostname to %s (from %s)", config
->remote_host, rpc->conn.config.remote_host); } while (
0)
1659 config->remote_host,do { do { if (0) printf ("changing hostname to %s (from %s)",
config->remote_host, rpc->conn.config.remote_host); } while
(0); _gf_log (rpc->conn.trans->name, "rpc-clnt.c", __FUNCTION__
, 1660, GF_LOG_INFO, "changing hostname to %s (from %s)", config
->remote_host, rpc->conn.config.remote_host); } while (
0)
1660 rpc->conn.config.remote_host)do { do { if (0) printf ("changing hostname to %s (from %s)",
config->remote_host, rpc->conn.config.remote_host); } while
(0); _gf_log (rpc->conn.trans->name, "rpc-clnt.c", __FUNCTION__
, 1660, GF_LOG_INFO, "changing hostname to %s (from %s)", config
->remote_host, rpc->conn.config.remote_host); } while (
0)
;
1661 FREE (rpc->conn.config.remote_host)if (rpc->conn.config.remote_host != ((void*)0)) { free ((void
*)rpc->conn.config.remote_host); rpc->conn.config.remote_host
= (void *)0xeeeeeeee; }
;
1662 } else {
1663 gf_log (rpc->conn.trans->name, GF_LOG_INFO,do { do { if (0) printf ("setting hostname to %s", config->
remote_host); } while (0); _gf_log (rpc->conn.trans->name
, "rpc-clnt.c", __FUNCTION__, 1665, GF_LOG_INFO, "setting hostname to %s"
, config->remote_host); } while (0)
1664 "setting hostname to %s",do { do { if (0) printf ("setting hostname to %s", config->
remote_host); } while (0); _gf_log (rpc->conn.trans->name
, "rpc-clnt.c", __FUNCTION__, 1665, GF_LOG_INFO, "setting hostname to %s"
, config->remote_host); } while (0)
1665 config->remote_host)do { do { if (0) printf ("setting hostname to %s", config->
remote_host); } while (0); _gf_log (rpc->conn.trans->name
, "rpc-clnt.c", __FUNCTION__, 1665, GF_LOG_INFO, "setting hostname to %s"
, config->remote_host); } while (0)
;
1666 }
1667
1668 rpc->conn.config.remote_host = gf_strdup (config->remote_host);
1669 }
1670}
1671
1672int
1673rpc_clnt_transport_unix_options_build (dict_t **options, char *filepath,
1674 int frame_timeout)
1675{
1676 dict_t *dict = NULL((void*)0);
1677 char *fpath = NULL((void*)0);
1678 int ret = -1;
1679
1680 GF_ASSERT (filepath)do { if (!(filepath)) { do { do { if (0) printf ("Assertion failed: "
"filepath"); } while (0); _gf_log_callingfn ("", "rpc-clnt.c"
, __FUNCTION__, 1680, GF_LOG_ERROR, "Assertion failed: " "filepath"
); } while (0); } } while (0)
;
1681 GF_ASSERT (options)do { if (!(options)) { do { do { if (0) printf ("Assertion failed: "
"options"); } while (0); _gf_log_callingfn ("", "rpc-clnt.c"
, __FUNCTION__, 1681, GF_LOG_ERROR, "Assertion failed: " "options"
); } while (0); } } while (0)
;
1682
1683 dict = dict_new ();
1684 if (!dict)
1685 goto out;
1686
1687 fpath = gf_strdup (filepath);
1688 if (!fpath) {
1689 ret = -1;
1690 goto out;
1691 }
1692
1693 ret = dict_set_dynstr (dict, "transport.socket.connect-path", fpath);
1694 if (ret)
1695 goto out;
1696
1697 ret = dict_set_str (dict, "transport.address-family", "unix");
1698 if (ret)
1699 goto out;
1700
1701 ret = dict_set_str (dict, "transport.socket.nodelay", "off");
1702 if (ret)
1703 goto out;
1704
1705 ret = dict_set_str (dict, "transport-type", "socket");
1706 if (ret)
1707 goto out;
1708
1709 ret = dict_set_str (dict, "transport.socket.keepalive", "off");
1710 if (ret)
1711 goto out;
1712
1713 if (frame_timeout > 0) {
1714 ret = dict_set_int32 (dict, "frame-timeout", frame_timeout);
1715 if (ret)
1716 goto out;
1717 }
1718
1719 *options = dict;
1720out:
1721 if (ret) {
1722 GF_FREE (fpath)__gf_free (fpath);
1723 if (dict)
1724 dict_unref (dict);
1725 }
1726 return ret;
1727}